Port from Python 2 to six

Signed-off-by: James Cameron <quozl@laptop.org>
This commit is contained in:
Pro-Panda
2018-03-01 17:28:56 +05:30
committed by James Cameron
parent 6345da8e07
commit aa8a5e70c4
74 changed files with 623 additions and 700 deletions
+4 -2
View File
@@ -44,7 +44,9 @@ an `[Activity]` header on the first line:
* `icon` - the icon file for the activity, shown by Sugar in the list
of installed activities,
* `exec` - how to execute the activity, e.g. `sugar-activity module.Class`,
* `exec` - how to execute the activity, e.g.
`sugar-activity3 module.Class` (For activities written for Python 3),
`sugar-activity module.Class` (For activities written for Python 2)
Optional metadata keys are;
@@ -117,7 +119,7 @@ Example `activity.info`
[Activity]
name = Browse
bundle_id = org.laptop.WebActivity
exec = sugar-activity webactivity.WebActivity -s
exec = sugar-activity3 webactivity.WebActivity -s
activity_version = 200
icon = activity-web
max_participants = 100
+2 -2
View File
@@ -20,7 +20,7 @@
UNSTABLE.
"""
from ConfigParser import ConfigParser, ParsingError
from six.moves.configparser import ConfigParser, ParsingError
from locale import normalize
import os
import shutil
@@ -441,7 +441,7 @@ class ActivityBundle(Bundle):
if delete_profile:
bundle_profile_path = env.get_profile_path(self._bundle_id)
if os.path.exists(bundle_profile_path):
os.chmod(bundle_profile_path, 0775)
os.chmod(bundle_profile_path, 0o775)
shutil.rmtree(bundle_profile_path, ignore_errors=True)
self._uninstall(install_path)
+5 -5
View File
@@ -20,10 +20,10 @@
UNSTABLE.
"""
import six
import os
import logging
import shutil
import StringIO
import zipfile
@@ -74,7 +74,7 @@ class Bundle(object):
if not os.path.isdir(self._path):
try:
self._zip_file = zipfile.ZipFile(self._path)
except zipfile.error, exception:
except zipfile.error as exception:
raise MalformedBundleException('Error accessing zip file %r: '
'%s' % (self._path, exception))
self._check_zip_bundle()
@@ -115,7 +115,7 @@ class Bundle(object):
if self._zip_file is None:
path = os.path.join(self._path, filename)
try:
f = open(path, 'rb')
f = open(path, 'r')
except IOError:
logging.debug("cannot open path %s" % path)
return None
@@ -123,7 +123,7 @@ class Bundle(object):
path = os.path.join(self._zip_root_dir, filename)
try:
data = self._zip_file.read(path)
f = StringIO.StringIO(data)
f = six.StringIO(data)
except KeyError:
logging.debug('%s not found in zip %s.' % (filename, path))
return None
@@ -171,7 +171,7 @@ class Bundle(object):
raise AlreadyInstalledException
if not os.path.isdir(install_dir):
os.mkdir(install_dir, 0775)
os.mkdir(install_dir, 0o775)
# zipfile provides API that in theory would let us do this
# correctly by hand, but handling all the oddities of
+1
View File
@@ -82,6 +82,7 @@ class NormalizedVersion(object):
Attributes:
parts (list): the numeric parts of the version after normalization.
"""
def __init__(self, activity_version):
self._activity_version = activity_version
self.parts = []
+4 -3
View File
@@ -21,10 +21,11 @@
UNSTABLE.
"""
from ConfigParser import ConfigParser
from six.moves import urllib
from six.moves.configparser import ConfigParser
import tempfile
import os
import urllib
from sugar3 import env
from sugar3.bundle.bundle import Bundle, MalformedBundleException
@@ -142,7 +143,7 @@ class ContentBundle(Bundle):
def get_start_uri(self):
path = os.path.join(self.get_path(), self._activity_start)
return 'file://' + urllib.pathname2url(path)
return 'file://' + urllib.request.pathname2url(path)
def get_bundle_id(self):
return self._global_name