Fix sugar-install-bundle

Traceback (most recent call last):
  File "/usr/bin/sugar-install-bundle", line 21, in <module>
    bundle = ActivityBundle(name)
  File "/usr/lib/python3.7/dist-packages/sugar3/bundle/activitybundle.py", line 118, in __init__
    info_file = self.get_file('activity/activity.info')
  File "/usr/lib/python3.7/dist-packages/sugar3/bundle/bundle.py", line 126, in get_file
    f = six.StringIO(data)
TypeError: initial_value must be str or None, not bytes

Fix by always reading bundle and metadata as Bytes, and converting to
String before passing to ConfigParser.

Did not fix ContentBundle, as it has been unused for some time, and was
only kept for use with OLPC XO and Python 2.
master
James Cameron 4 years ago
parent e41c3a5f35
commit 2018c930ad

@ -129,7 +129,7 @@ class ActivityBundle(Bundle):
def _parse_info(self, info_file): def _parse_info(self, info_file):
cp = ConfigParser() cp = ConfigParser()
cp.readfp(info_file) cp.read_string(info_file.read().decode())
section = 'Activity' section = 'Activity'
@ -251,7 +251,7 @@ class ActivityBundle(Bundle):
def _parse_linfo(self, linfo_file): def _parse_linfo(self, linfo_file):
cp = ConfigParser() cp = ConfigParser()
try: try:
cp.readfp(linfo_file) cp.read_string(linfo_file.read().decode())
section = 'Activity' section = 'Activity'

@ -115,7 +115,7 @@ class Bundle(object):
if self._zip_file is None: if self._zip_file is None:
path = os.path.join(self._path, filename) path = os.path.join(self._path, filename)
try: try:
f = open(path, 'r') f = open(path, 'rb')
except IOError: except IOError:
logging.debug("cannot open path %s" % path) logging.debug("cannot open path %s" % path)
return None return None
@ -123,7 +123,7 @@ class Bundle(object):
path = os.path.join(self._zip_root_dir, filename) path = os.path.join(self._zip_root_dir, filename)
try: try:
data = self._zip_file.read(path) data = self._zip_file.read(path)
f = six.StringIO(data) f = six.BytesIO(data)
except KeyError: except KeyError:
logging.debug('%s not found in zip %s.' % (filename, path)) logging.debug('%s not found in zip %s.' % (filename, path))
return None return None

Loading…
Cancel
Save