sugarlabs / sugar-toolkit-gtk3

Sugar Learning Environment, Activity Toolkit, GTK 3.
GNU Lesser General Public License v2.1
21 stars 80 forks source link

unicode issue in bundlebuilder.py #425

Closed bhulsken closed 5 years ago

bhulsken commented 5 years ago

GNU message catalog files are binary, and should not be opened as unicode, which is what happens when using python3, it gives this error:

./setup.py install
Traceback (most recent call last):
  File "./setup.py", line 21, in <module>
    bundlebuilder.start()
  File "/usr/lib/python3.7/site-packages/sugar3/activity/bundlebuilder.py", line 633, in start
    globals()['cmd_' + options.command](config, options)
  File "/usr/lib/python3.7/site-packages/sugar3/activity/bundlebuilder.py", line 513, in cmd_install
    options.install_desktop_file)
  File "/usr/lib/python3.7/site-packages/sugar3/activity/bundlebuilder.py", line 283, in install
    self.builder.build()
  File "/usr/lib/python3.7/site-packages/sugar3/activity/bundlebuilder.py", line 126, in build
    self.build_locale()
  File "/usr/lib/python3.7/site-packages/sugar3/activity/bundlebuilder.py", line 158, in build_locale
    cat = gettext.GNUTranslations(open(mo_file, 'r'))
  File "/usr/lib64/python3.7/gettext.py", line 260, in __init__
    self._parse(fp)
  File "/usr/lib64/python3.7/gettext.py", line 350, in _parse
    buf = fp.read()
  File "/usr/lib64/python3.7/codecs.py", line 322, in decode
    (result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xde in position 0: invalid continuation byte

the solution is to open the catalog file as binary with 'rb', patch below works for me.

best regards, Bas Hulsken

diff -Naupr sugar-toolkit-gtk3/src/sugar3/activity/bundlebuilder.py sugar-toolkit-gtk3-fix/src/sugar3/activity/bundlebuilder.py
--- sugar-toolkit-gtk3/src/sugar3/activity/bundlebuilder.py     2019-03-16 14:21:20.218390727 +0100
+++ sugar-toolkit-gtk3-fix/src/sugar3/activity/bundlebuilder.py 2019-08-11 15:39:37.639162986 +0200
@@ -155,7 +155,7 @@ class Builder(object):
                 if self._no_fail:
                     continue

-            cat = gettext.GNUTranslations(open(mo_file, 'r'))
+            cat = gettext.GNUTranslations(open(mo_file, 'rb'))
             translated_name = cat.gettext(self.config.activity_name)
             translated_summary = cat.gettext(self.config.summary)
             if translated_summary is None:
bhulsken commented 5 years ago

apologies, github mangled the patch, here's an attached version

gnutranslationsunicodefix.patch.txt

quozl commented 5 years ago

Thanks. Demangled your comment; added three backticks before and after. Pushed as a62bb885. Couldn't find your mail address to properly set --author, but did use your name; let me know if you'd like mail address added.