Hi Shawn,

As per your suggestion moved the result_l10n dictionary to result_text() method in history.py file. The dictionary is initialized only once. Thanks for offline review of
this change.

Here is updated webrev : https://cr.opensolaris.org/action/browse/pkg/ae112802/7166082-rev4/webrev/

I have also attached the patch. Could you please push it.

Thanks,
Abhi.

On 07/02/12 18:07, Abhinandan Ekande wrote:
Hi Danek,

Agree that only one module is getting fixed with this approach.
I will implement either Shawn's or your suggestion and post the
webrev.

Thanks,
Abhi.

On 06/30/12 17:18, Takeshi Asano wrote:
Hi Danek,

I see your point. Thank you.

Yes, once the gettext.install() call is removed history.py will be
in same state as the other modules. Use of gettext.translation()
can be addressed separately for all modules.

Thanks,
Takeshi

On 2012年06月30日 09:52, Danek Duvall wrote:
Takeshi Asano wrote:

The new code doesn't rely on application's gettext.install() call.
The client/__init__.py does the per-module definition of "_"
and client/history.py imports that.

I realize that the latest proposal does the right thing, but the rest of the modules don't, and the proposal is to fix just this module. I don't like the partial solution. Either fix it all, or don't fix this particular problem, and get around the fact that history.py i18ns some strings at the
module level in a different way.

Danek

_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss
# HG changeset patch
# User [email protected]
# Date 1341808384 -19800
# Node ID 6de5cf08614c72c0142fe574123921dfb93d4234
# Parent  9cbeedd42e78b4bbb219a266683ee4137c3d8d02
7166082 pkg command does not handle Japanese character encoding on Solaris 11

diff -r 9cbeedd42e78 -r 6de5cf08614c src/client.py
--- a/src/client.py     Wed Jul 04 21:11:40 2012 +1200
+++ b/src/client.py     Mon Jul 09 10:03:04 2012 +0530
@@ -6602,7 +6602,8 @@
 
 if __name__ == "__main__":
         misc.setlocale(locale.LC_ALL, "", error)
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         # Make all warnings be errors.
         import warnings
diff -r 9cbeedd42e78 -r 6de5cf08614c src/depot.py
--- a/src/depot.py      Wed Jul 04 21:11:40 2012 +1200
+++ b/src/depot.py      Mon Jul 09 10:03:04 2012 +0530
@@ -19,7 +19,7 @@
 #
 # CDDL HEADER END
 #
-# Copyright (c) 2007, 2011 Oracle and/or its affiliates.  All rights reserved.
+# Copyright (c) 2007, 2012, Oracle and/or its affiliates.  All rights reserved.
 #
 
 # pkg.depotd - package repository daemon
@@ -228,7 +228,8 @@
 if __name__ == "__main__":
 
         setlocale(locale.LC_ALL, "")
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         add_content = False
         exit_ready = False
diff -r 9cbeedd42e78 -r 6de5cf08614c src/modules/client/history.py
--- a/src/modules/client/history.py     Wed Jul 04 21:11:40 2012 +1200
+++ b/src/modules/client/history.py     Mon Jul 09 10:03:04 2012 +0530
@@ -26,8 +26,6 @@
 
 import copy
 import errno
-import gettext
-import locale
 import os
 import shutil
 import sys
@@ -104,31 +102,6 @@
     MemoryError: RESULT_FAILED_OUTOFMEMORY,
 }
 
-misc.setlocale(locale.LC_ALL, "")
-gettext.install("pkg", "/usr/share/locale")
-
-# since we store english text in our XML files, we need a way for clients
-# obtain a translated version of these messages.
-result_l10n = {
-    "Canceled": _("Canceled"),
-    "Failed": _("Failed"),
-    "Ignored": _("Ignored"),
-    "Nothing to do": _("Nothing to do"),
-    "Succeeded": _("Succeeded"),
-    "Bad Request": _("Bad Request"),
-    "Configuration": _("Configuration"),
-    "Constrained": _("Constrained"),
-    "Locked": _("Locked"),
-    "Search": _("Search"),
-    "Storage": _("Storage"),
-    "Transport": _("Transport"),
-    "Actuator": _("Actuator"),
-    "Out of Memory": _("Out of Memory"),
-    "Conflicting Actions": _("Conflicting Actions"),
-    "Unknown": _("Unknown"),
-    "None": _("None")
-}
-
 class _HistoryOperation(object):
         """A _HistoryOperation object is a representation of data about an
         operation that a pkg(5) client has performed.  This class is private
@@ -139,6 +112,8 @@
         manipulated as they are set or retrieved.
         """
 
+        result_l10n = {}    # Static variable for dictionary
+
         def __copy__(self):
                 h = _HistoryOperation()
                 for attr in ("name", "start_time", "end_time", "start_state",
@@ -235,10 +210,35 @@
         def result_text(self):
                 """Returns a tuple containing the translated text for the
                 operation result of the form (outcome, reason)."""
+
+                if not _HistoryOperation.result_l10n:
+                        # since we store english text in our XML files, we
+                        # need a way for clients obtain a translated version
+                        # of these messages.
+                        _HistoryOperation.result_l10n = {
+                            "Canceled": _("Canceled"),
+                            "Failed": _("Failed"),
+                            "Ignored": _("Ignored"),
+                            "Nothing to do": _("Nothing to do"),
+                            "Succeeded": _("Succeeded"),
+                            "Bad Request": _("Bad Request"),
+                            "Configuration": _("Configuration"),
+                            "Constrained": _("Constrained"),
+                            "Locked": _("Locked"),
+                            "Search": _("Search"),
+                            "Storage": _("Storage"),
+                            "Transport": _("Transport"),
+                            "Actuator": _("Actuator"),
+                            "Out of Memory": _("Out of Memory"),
+                            "Conflicting Actions": _("Conflicting Actions"),
+                            "Unknown": _("Unknown"),
+                            "None": _("None")
+                        }
+
                 if not self.start_time or not self.result:
                         return ("", "")
-                return (result_l10n[self.result[0]],
-                    result_l10n[self.result[1]])
+                return (_HistoryOperation.result_l10n[self.result[0]],
+                    _HistoryOperation.result_l10n[self.result[1]])
 
 
 class History(object):
diff -r 9cbeedd42e78 -r 6de5cf08614c 
src/pkg/manifests/developer:opensolaris:pkg5.p5m
--- a/src/pkg/manifests/developer:opensolaris:pkg5.p5m  Wed Jul 04 21:11:40 
2012 +1200
+++ b/src/pkg/manifests/developer:opensolaris:pkg5.p5m  Mon Jul 09 10:03:04 
2012 +0530
@@ -48,6 +48,7 @@
 depend type=require fmri=pkg:/runtime/python-27
 depend type=require fmri=pkg:/system/header
 depend type=require fmri=pkg:/system/linker
+depend type=require fmri=pkg:/system/locale/extra
 depend type=require fmri=pkg:/text/locale
 depend type=require fmri=pkg:/text/tidy
 depend type=require fmri=pkg:/web/server/apache-22
diff -r 9cbeedd42e78 -r 6de5cf08614c src/pkgdep.py
--- a/src/pkgdep.py     Wed Jul 04 21:11:40 2012 +1200
+++ b/src/pkgdep.py     Mon Jul 09 10:03:04 2012 +0530
@@ -535,7 +535,8 @@
 
 def main_func():
         misc.setlocale(locale.LC_ALL, "", error)
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         try:
                 opts, pargs = getopt.getopt(sys.argv[1:], "R:?",
diff -r 9cbeedd42e78 -r 6de5cf08614c src/pkgrepo.py
--- a/src/pkgrepo.py    Wed Jul 04 21:11:40 2012 +1200
+++ b/src/pkgrepo.py    Mon Jul 09 10:03:04 2012 +0530
@@ -1290,7 +1290,8 @@
 
 if __name__ == "__main__":
         misc.setlocale(locale.LC_ALL, "", error)
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         # Make all warnings be errors.
         warnings.simplefilter('error')
diff -r 9cbeedd42e78 -r 6de5cf08614c src/publish.py
--- a/src/publish.py    Wed Jul 04 21:11:40 2012 +1200
+++ b/src/publish.py    Mon Jul 09 10:03:04 2012 +0530
@@ -27,6 +27,7 @@
 import fnmatch
 import getopt
 import gettext
+import locale
 import os
 import sys
 import traceback
@@ -695,7 +696,8 @@
         return xport, targ_pub
 
 def main_func():
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         repo_uri = os.getenv("PKG_REPO", None)
 
diff -r 9cbeedd42e78 -r 6de5cf08614c src/pull.py
--- a/src/pull.py       Wed Jul 04 21:11:40 2012 +1200
+++ b/src/pull.py       Mon Jul 09 10:03:04 2012 +0530
@@ -28,6 +28,7 @@
 import errno
 import getopt
 import gettext
+import locale
 import os
 import shutil
 import sys
@@ -359,7 +360,8 @@
 
         temp_root = misc.config_temp_root()
 
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         global_settings.client_name = "pkgrecv"
         target = os.environ.get("PKG_DEST", None)
diff -r 9cbeedd42e78 -r 6de5cf08614c src/sign.py
--- a/src/sign.py       Wed Jul 04 21:11:40 2012 +1200
+++ b/src/sign.py       Mon Jul 09 10:03:04 2012 +0530
@@ -21,7 +21,7 @@
 #
 
 #
-# Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 
 import getopt
@@ -114,7 +114,8 @@
 
 def main_func():
         misc.setlocale(locale.LC_ALL, "", error)
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
         global_settings.client_name = "pkgsign"
 
         try:
diff -r 9cbeedd42e78 -r 6de5cf08614c src/sysrepo.py
--- a/src/sysrepo.py    Wed Jul 04 21:11:40 2012 +1200
+++ b/src/sysrepo.py    Mon Jul 09 10:03:04 2012 +0530
@@ -919,7 +919,8 @@
 
 if __name__ == "__main__":
         misc.setlocale(locale.LC_ALL, "", error)
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         # Make all warnings be errors.
         warnings.simplefilter('error')
diff -r 9cbeedd42e78 -r 6de5cf08614c src/tests/cli/t_pkg_help.py
--- a/src/tests/cli/t_pkg_help.py       Wed Jul 04 21:11:40 2012 +1200
+++ b/src/tests/cli/t_pkg_help.py       Mon Jul 09 10:03:04 2012 +0530
@@ -20,16 +20,21 @@
 # CDDL HEADER END
 #
 
-# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
 
 import testutils
 if __name__ == "__main__":
         testutils.setup_environment("../../../proto")
 import pkg5unittest
 
+import codecs
+import os
+import re
 import unittest
 
 class TestPkgHelp(pkg5unittest.CliTestCase):
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
 
         def test_help(self):
                 """Verify that usage message works regardless of how it is
@@ -83,5 +88,46 @@
                             "pkg [options] command [cmd_options] [operands]",
                             "PKG_IMAGE"])
 
+        def test_help_character_encoding(self):
+                """Verify help command output for ja_JP.eucJP locale.
+                Match against the expected output"""
+
+                # This is a test case for CR 7166082.
+                # It compares the output of "pkg --help" command against
+                # the expected output for ja_JP.eucJP locale.
+                # If first 4 lines of "pkg --help" command output modified
+                # in the future then this test case will also need to be
+                # modified.
+
+                ret, out = self.cmdline_run("/usr/bin/locale -a", out=True)
+                line = " ".join(out.split())
+                m = re.search(r"ja_JP.eucJP", line)
+                self.assert_(m, "You must have ja_JP.eucJP"
+                    " locale installed for this test to succeed.")
+
+                eucJP_encode_file = os.path.join(self.ro_data_root,
+                    "pkg.help.eucJP.expected.out")
+                f = codecs.open(eucJP_encode_file, encoding="eucJP")
+
+                locale_env = { "LC_ALL": "ja_JP.eucJP" }
+                ret, out, err = self.pkg("--help", env_arg=locale_env,
+                    out=True, stderr=True)
+                cmd_out = unicode(err, encoding="eucJP")
+                # Take only 4 lines from "pkg --help" command output.
+                u_out = cmd_out.splitlines()[:4]
+
+                n = 0
+                # The expected output file contain 4 lines and command output
+                # is also 4 lines.
+                while n < 4:
+                        cmd_line = u_out[n]
+                        # Remove \n from readline()
+                        file_line = f.readline()[:-1]
+
+                        self.assertEqual(cmd_line, file_line)
+                        n = n + 1
+
+                f.close()
+
 if __name__ == "__main__":
         unittest.main()
diff -r 9cbeedd42e78 -r 6de5cf08614c 
src/tests/ro_data/pkg.help.eucJP.expected.out
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/src/tests/ro_data/pkg.help.eucJP.expected.out     Mon Jul 09 10:03:04 
2012 +0530
@@ -0,0 +1,4 @@
+»ÈÍÑÊýË¡:
+        pkg [options] command [cmd_options] [operands]
+
+´ðËÜŪ¤Ê¥µ¥Ö¥³¥Þ¥ó¥É:
diff -r 9cbeedd42e78 -r 6de5cf08614c src/util/publish/pkgdiff.py
--- a/src/util/publish/pkgdiff.py       Wed Jul 04 21:11:40 2012 +1200
+++ b/src/util/publish/pkgdiff.py       Mon Jul 09 10:03:04 2012 +0530
@@ -26,6 +26,7 @@
 
 import getopt
 import gettext
+import locale
 import sys
 import traceback
 
@@ -59,7 +60,8 @@
                 sys.exit(exitcode)
 
 def main_func():
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         ignoreattrs = []
         onlyattrs = []
diff -r 9cbeedd42e78 -r 6de5cf08614c src/util/publish/pkgfmt.py
--- a/src/util/publish/pkgfmt.py        Wed Jul 04 21:11:40 2012 +1200
+++ b/src/util/publish/pkgfmt.py        Mon Jul 09 10:03:04 2012 +0530
@@ -20,7 +20,7 @@
 # CDDL HEADER END
 
 #
-# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 
 # Prefixes should be ordered alphabetically with most specific first.
@@ -56,6 +56,7 @@
         import errno
         import getopt
         import gettext
+        import locale
         import operator
         import os
         import re
@@ -489,7 +490,8 @@
         print >> fileobj, output
 
 def main_func():
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
         global opt_unwrap
         global opt_check
         global opt_diffs
diff -r 9cbeedd42e78 -r 6de5cf08614c src/util/publish/pkglint.py
--- a/src/util/publish/pkglint.py       Wed Jul 04 21:11:40 2012 +1200
+++ b/src/util/publish/pkglint.py       Mon Jul 09 10:03:04 2012 +0530
@@ -21,18 +21,17 @@
 #
     
 #
-# Copyright (c) 2010, 2011 Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 
 import codecs
 import logging
 import sys
 import gettext
+import locale
 import traceback
 from optparse import OptionParser
 
-gettext.install("pkg", "/usr/share/locale")
-
 from pkg.client.api_errors import InvalidPackageErrors
 from pkg import VERSION
 from pkg.misc import PipeError
@@ -57,6 +56,9 @@
 def main_func():
         """Start pkglint."""
 
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
+
         global logger
         
         usage = \
diff -r 9cbeedd42e78 -r 6de5cf08614c src/util/publish/pkgmerge.py
--- a/src/util/publish/pkgmerge.py      Wed Jul 04 21:11:40 2012 +1200
+++ b/src/util/publish/pkgmerge.py      Mon Jul 09 10:03:04 2012 +0530
@@ -859,7 +859,8 @@
 
 if __name__ == "__main__":
         misc.setlocale(locale.LC_ALL, "", error)
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         # Make all warnings be errors.
         import warnings
diff -r 9cbeedd42e78 -r 6de5cf08614c src/util/publish/pkgmogrify.py
--- a/src/util/publish/pkgmogrify.py    Wed Jul 04 21:11:40 2012 +1200
+++ b/src/util/publish/pkgmogrify.py    Mon Jul 09 10:03:04 2012 +0530
@@ -20,11 +20,12 @@
 # CDDL HEADER END
 
 #
-# Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved.
 #
 
 import getopt
 import gettext
+import locale
 import os
 import re
 import shlex
@@ -661,7 +662,8 @@
                 sys.exit(exitcode)
 
 def main_func():
-        gettext.install("pkg", "/usr/share/locale")
+        gettext.install("pkg", "/usr/share/locale",
+            codeset=locale.getpreferredencoding())
 
         outfilename = None
         printfilename = None
_______________________________________________
pkg-discuss mailing list
[email protected]
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to