On 07/10/12 03:28 AM, Danek Duvall wrote:
Saurabh Vyas wrote:

https://cr.opensolaris.org/action/browse/pkg/saurabhv/CR-7127117-rev3/webrev/

misc.py:

   - line 2424: rename the function to "decode", which is more appropriate
     for a more visible function like it is now.  I'm sure there's a better
     name than that, too, but nothing's coming to mind.

   - line 2435: drop the trailing blank line.

Otherwise, looks fine to me.

Thanks Danek for review, I have made the above changes.

Please find attached patch for this fix.

Thanks,
Saurabh


Thanks,
Danek


--


Saurabh Vyas
Solaris Install Group,
Revenue Product Engineering (RPE), Systems |Bangalore |
Green Oracle <http://www.oracle.com/commitment> Oracle is committed to
developing practices and products that help protect the environment
# HG changeset patch
# User saurabh.v...@oracle.com
# Date 1341886285 -19800
# Node ID 9a9fd8190e14b571e174454a6ed1de32ce9c5de1
# Parent  dcc301c4edad7b4f14181983d89e983a9883635b
7127117 pkg update --parsable option is not working

diff --git a/src/client.py b/src/client.py
--- a/src/client.py
+++ b/src/client.py
@@ -1212,13 +1212,15 @@
                     plan.get_licenses():
                         src_tup = None
                         if src_li:
+                                li_txt = misc.decode(src_li.get_text())
                                 src_tup = (str(src_li.fmri), src_li.license,
-                                    src_li.get_text(), src_li.must_accept,
+                                    li_txt, src_li.must_accept,
                                     src_li.must_display)
                         dest_tup = None
                         if dest_li:
+                                li_txt = misc.decode(dest_li.get_text())
                                 dest_tup = (str(dest_li.fmri),
-                                    dest_li.license, dest_li.get_text(),
+                                    dest_li.license, li_txt,
                                     dest_li.must_accept, dest_li.must_display)
                         licenses.append(
                             (str(dfmri), src_tup, dest_tup))
diff --git a/src/modules/client/imageplan.py b/src/modules/client/imageplan.py
--- a/src/modules/client/imageplan.py
+++ b/src/modules/client/imageplan.py
@@ -2071,18 +2071,6 @@
                 must_display = False
                 notes = []
 
-                def do_decode(s):
-                        """convert non-ascii strings to unicode;
-                        replace non-convertable chars"""
-                        try:
-                                # this will fail if any 8 bit chars in string
-                                # this is a nop if string is ascii.
-                                s = s.encode("ascii")
-                        except ValueError:
-                                # this will encode 8 bit strings into unicode
-                                s = s.decode("utf-8", "replace")
-                        return s
-
                 if release_notes:
                         installed_dict = ImagePlan.__fmris2dict(
                             self.image.gen_installed_pkgs())
@@ -2094,7 +2082,7 @@
                                                 must_display = True
                                         for l in self.__get_note_text(
                                             act, pfmri).splitlines():
-                                                notes.append(do_decode(l))
+                                                notes.append(misc.decode(l))
                                         
                         self.pd.release_notes = (must_display, notes)
 
diff --git a/src/modules/misc.py b/src/modules/misc.py
--- a/src/modules/misc.py
+++ b/src/modules/misc.py
@@ -2420,3 +2420,15 @@
                 return
 
         return runtime_proxy
+
+def decode(s):
+        """convert non-ascii strings to unicode;
+        replace non-convertable chars"""
+        try:
+                # this will fail if any 8 bit chars in string
+                # this is a nop if string is ascii.
+                s = s.encode("ascii")
+        except ValueError:
+                # this will encode 8 bit strings into unicode
+                s = s.decode("utf-8", "replace")
+        return s
diff --git a/src/tests/cli/t_pkg_install.py b/src/tests/cli/t_pkg_install.py
--- a/src/tests/cli/t_pkg_install.py
+++ b/src/tests/cli/t_pkg_install.py
@@ -6309,6 +6309,9 @@
 
         persistent_depot = True
 
+        # Tests in this suite use the read only data directory.
+        need_ro_data = True
+
         baz10 = """
             open baz@1.0,5.11-0
             add license copyright.baz license=copyright.baz
@@ -6343,12 +6346,47 @@
         misc_files = ["copyright.baz", "copyright.licensed", "libc.so.1",
             "license.licensed", "license.licensed.addendum"]
 
+        # Packages with copyright in non-ascii character
+        nonascii10 = """
+            open nonascii@1.0,5.11-0
+            add license 88591enc.copyright license=copyright
+            close """
+
+        # Packages with copyright in non-ascii character
+        utf8enc10 = """
+            open utf8enc@1.0,5.11-0
+            add license utf8enc.copyright license=copyright
+            close """
+
+        # Packages with copyright in unsupported character set
+        unsupported10 = """
+            open unsupported@1.0,5.11-0
+            add license unsupported.copyright license=copyright
+            close """
+
         def setUp(self):
                 pkg5unittest.SingleDepotTestCase.setUp(self, 
publisher="bobcat")
                 self.make_misc_files(self.misc_files)
 
+                # Use license with latin1 i.e 88591 encoding
+                n_copyright = os.path.join(self.ro_data_root,
+                    "88591enc.copyright")
+                self.make_misc_files({"88591enc.copyright": n_copyright})
+
+                # Use utf-8 encoding license
+                utf_copyright = os.path.join(self.ro_data_root,
+                    "utf8enc.copyright")
+                self.make_misc_files({"utf8enc.copyright": utf_copyright})
+
+                # Use unsupported license
+                u_copyright = os.path.join(self.ro_data_root,
+                    "unsupported.copyright")
+                self.make_misc_files({"unsupported.copyright": u_copyright})
+
                 self.plist = self.pkgsend_bulk(self.rurl, (self.licensed10,
-                    self.licensed12, self.licensed13, self.baz10))
+                    self.licensed12, self.licensed13, self.baz10,
+                    self.nonascii10, self.utf8enc10, self.unsupported10))
+
 
         def test_01_install_update(self):
                 """Verifies that install and update handle license
@@ -6421,6 +6459,15 @@
                             "license.licensed", True, False]]])
                 self.pkg("info licensed@1.3")
 
+        def test_02_bug_7127117(self):
+                """Verifies that install with --parsable handles licenses
+                with non-ascii & non UTF locale"""
+                self.image_create(self.rurl, prefix="bobcat")
+
+                self.pkg("install --parsable=0 nonascii@1.0")
+                self.pkg("install --parsable=0 utf8enc@1.0")
+                self.pkg("install --parsable=0 unsupported@1.0")
+
 
 class TestActionErrors(pkg5unittest.SingleDepotTestCase):
         """This set of tests is intended to verify that the client will handle
diff --git a/src/tests/ro_data/88591enc.copyright 
b/src/tests/ro_data/88591enc.copyright
new file mode 100644
--- /dev/null
+++ b/src/tests/ro_data/88591enc.copyright
@@ -0,0 +1,2 @@
+Copyright ? 1998-2009 by Contributors. All Rights Reserved.
+This copyright is for test purpose.
diff --git a/src/tests/ro_data/unsupported.copyright 
b/src/tests/ro_data/unsupported.copyright
new file mode 100644
--- /dev/null
+++ b/src/tests/ro_data/unsupported.copyright
@@ -0,0 +1,2 @@
+????????:
+This copyright is for test purpose.
diff --git a/src/tests/ro_data/utf8enc.copyright 
b/src/tests/ro_data/utf8enc.copyright
new file mode 100644
--- /dev/null
+++ b/src/tests/ro_data/utf8enc.copyright
@@ -0,0 +1,2 @@
+Copyright ?? 1998-2009 by Contributors. All Rights Reserved.
+This copyright is for test purpose.
_______________________________________________
pkg-discuss mailing list
pkg-discuss@opensolaris.org
http://mail.opensolaris.org/mailman/listinfo/pkg-discuss

Reply via email to