pylint sugar.bundle

master
Marco Pesenti Gritti 16 years ago
parent 050e9b54c3
commit 7b485120a3

@ -217,8 +217,9 @@ class ActivityBundle(Bundle):
return False
def install(self):
activities_path = env.get_user_activities_path()
act = activity.get_registry().get_activity(self._bundle_id)
if act is not None and act.path.startswith(env.get_user_activities_path()):
if act is not None and act.path.startswith(activities_path):
raise AlreadyInstalledException
install_dir = env.get_user_activities_path()
@ -226,7 +227,8 @@ class ActivityBundle(Bundle):
install_path = os.path.join(install_dir, self._zip_root_dir)
xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
xdg_data_home = os.getenv('XDG_DATA_HOME',
os.path.expanduser('~/.local/share'))
mime_path = os.path.join(install_path, 'activity', 'mimetypes.xml')
if os.path.isfile(mime_path):
@ -234,7 +236,8 @@ class ActivityBundle(Bundle):
mime_pkg_dir = os.path.join(mime_dir, 'packages')
if not os.path.isdir(mime_pkg_dir):
os.makedirs(mime_pkg_dir)
installed_mime_path = os.path.join(mime_pkg_dir, '%s.xml' % self._bundle_id)
installed_mime_path = os.path.join(mime_pkg_dir,
'%s.xml' % self._bundle_id)
os.symlink(mime_path, installed_mime_path)
os.spawnlp(os.P_WAIT, 'update-mime-database',
'update-mime-database', mime_dir)
@ -272,7 +275,7 @@ class ActivityBundle(Bundle):
act = activity.get_registry().get_activity(self._bundle_id)
if not force and act.version != self._activity_version:
logging.warning('Not uninstalling because different bundle present')
logging.warning('Not uninstalling, different bundle present')
return
elif not act.path.startswith(env.get_user_activities_path()):
logging.warning('Not uninstalling system activity')
@ -281,10 +284,12 @@ class ActivityBundle(Bundle):
install_path = os.path.join(env.get_user_activities_path(),
self._zip_root_dir)
xdg_data_home = os.getenv('XDG_DATA_HOME', os.path.expanduser('~/.local/share'))
xdg_data_home = os.getenv('XDG_DATA_HOME',
os.path.expanduser('~/.local/share'))
mime_dir = os.path.join(xdg_data_home, 'mime')
installed_mime_path = os.path.join(mime_dir, 'packages', '%s.xml' % self._bundle_id)
installed_mime_path = os.path.join(mime_dir, 'packages',
'%s.xml' % self._bundle_id)
if os.path.exists(installed_mime_path):
os.remove(installed_mime_path)
os.spawnlp(os.P_WAIT, 'update-mime-database',
@ -294,8 +299,8 @@ class ActivityBundle(Bundle):
if mime_types is not None:
installed_icons_dir = os.path.join(xdg_data_home,
'icons/sugar/scalable/mimetypes')
for file in os.listdir(installed_icons_dir):
path = os.path.join(installed_icons_dir, file)
for f in os.listdir(installed_icons_dir):
path = os.path.join(installed_icons_dir, f)
if os.path.islink(path) and \
os.readlink(path).startswith(install_path):
os.remove(path)
@ -313,9 +318,11 @@ class ActivityBundle(Bundle):
try:
self.uninstall(force=True)
except Exception, e:
logging.warning('Uninstall failed (%s), still trying to install newer bundle', e)
logging.warning('Uninstall failed (%s), still trying ' \
'to install newer bundle', e)
else:
logging.warning('Unable to uninstall system activity, installing upgraded version in user activities')
logging.warning('Unable to uninstall system activity, ' \
'installing upgraded version in user activities')
self.install()

@ -18,15 +18,27 @@
"""Sugar bundle file handler"""
import os
import logging
import StringIO
import zipfile
class AlreadyInstalledException(Exception): pass
class NotInstalledException(Exception): pass
class InvalidPathException(Exception): pass
class ZipExtractException(Exception): pass
class RegistrationException(Exception): pass
class MalformedBundleException(Exception): pass
class AlreadyInstalledException(Exception):
pass
class NotInstalledException(Exception):
pass
class InvalidPathException(Exception):
pass
class ZipExtractException(Exception):
pass
class RegistrationException(Exception):
pass
class MalformedBundleException(Exception):
pass
class Bundle:
"""A Sugar activity, content module, etc.
@ -38,8 +50,13 @@ class Bundle:
This is an abstract base class. See ActivityBundle and
ContentBundle for more details on those bundle types.
"""
_zipped_extension = None
_unzipped_extension = None
def __init__(self, path):
self._path = path
self._zip_root_dir = None
if os.path.isdir(self._path):
self._unpacked = True
@ -66,7 +83,7 @@ class Bundle:
self._zip_root_dir = file_names[0].split('/')[0]
if self._unzipped_extension is not None:
(name, ext) = os.path.splitext(self._zip_root_dir)
ext = os.path.splitext(self._zip_root_dir)[0]
if ext != self._unzipped_extension:
raise MalformedBundleException(
'All files in the bundle must be inside a single ' +
@ -80,24 +97,23 @@ class Bundle:
'top-level directory')
def _get_file(self, filename):
file = None
f = None
if self._unpacked:
path = os.path.join(self._path, filename)
if os.path.isfile(path):
file = open(path)
f = open(path)
else:
zip_file = zipfile.ZipFile(self._path)
path = os.path.join(self._zip_root_dir, filename)
try:
data = zip_file.read(path)
file = StringIO.StringIO(data)
f = StringIO.StringIO(data)
except KeyError:
# == "file not found"
pass
logging.log('%s not found.' % filename)
zip_file.close()
return file
return f
def get_path(self):
"""Get the bundle path."""
@ -123,12 +139,7 @@ class Bundle:
if not self._unpacked:
raise NotInstalledException
# FIXME: use manifest
zip = zipfile.ZipFile(bundle_path, 'w', zipfile.ZIP_DEFLATED)
for root, dirs, files in os.walk(self._path):
for name in files:
zip.write(filename, os.path.join(base_dir, filename))
zip.close()
raise NotImplementedError
def _uninstall(self, install_path):
if not os.path.isdir(install_path):

@ -39,6 +39,16 @@ class ContentBundle(Bundle):
def __init__(self, path):
Bundle.__init__(self, path)
self._locale = None
self._l10n = None
self._category = None
self._name = None
self._subcategory = None
self._category_class = None
self._category_icon = None
self._library_version = None
self._bundle_class = None
info_file = self._get_file('library/library.info')
if info_file is None:
raise MalformedBundleException('No library.info file')
@ -145,9 +155,6 @@ class ContentBundle(Bundle):
def get_category(self):
return self._category
def get_category(self):
return self._category
def get_category_icon(self):
return self._category_icon
@ -161,9 +168,11 @@ class ContentBundle(Bundle):
return self._bundle_class
def _run_indexer(self):
os.spawnlp(os.P_WAIT, 'python',
'python',
env.get_prefix_path('share/library-common/make_index.py'))
if os.environ.has_key('XDG_DATA_DIRS'):
for path in os.environ['XDG_DATA_DIRS'].split(':'):
indexer = os.path.join(path, 'library-common', 'make_index.py')
if os.path.exists(indexer):
os.spawnlp(os.P_WAIT, 'python', 'python', indexer)
def is_installed(self):
if self._unpacked:

Loading…
Cancel
Save