ContentBundle cleanups

Share get_installation_time() between all bundle types so that it works
with content bundles.

Add get_tags() stub, this is called by Sugar.

Remove unused fields: l10n, category, subcategory, etc.

We remove support for running OLPC's content bundle indexer.
This is assumed to go away now that Sugar will support content bundles
as first-class objects.

Some minor behavioural fixes and cleanups.

This now implements http://wiki.sugarlabs.org/go/Content_bundles
and when care is taken to include all the fields required by old
Sugar versions, there is no change in compatibility of existing or
new content bundles.

Required for http://wiki.sugarlabs.org/go/Features/Content_support
This commit is contained in:
Daniel Drake 2013-07-03 13:46:46 -06:00 committed by Daniel Narvaez
parent 363eef5293
commit f46ac7ba6a
3 changed files with 43 additions and 110 deletions

View File

@ -107,7 +107,6 @@ class ActivityBundle(Bundle):
self._show_launcher = True self._show_launcher = True
self._tags = None self._tags = None
self._activity_version = '0' self._activity_version = '0'
self._installation_time = os.stat(path).st_mtime
self._summary = None self._summary = None
info_file = self.get_file('activity/activity.info') info_file = self.get_file('activity/activity.info')
@ -230,11 +229,6 @@ class ActivityBundle(Bundle):
"""Get the activity user-visible name.""" """Get the activity user-visible name."""
return self._name return self._name
def get_installation_time(self):
"""Get a timestamp representing the time at which this activity was
installed."""
return self._installation_time
def get_bundle_id(self): def get_bundle_id(self):
"""Get the activity bundle id""" """Get the activity bundle id"""
return self._bundle_id return self._bundle_id

View File

@ -69,6 +69,7 @@ class Bundle(object):
self._path = path self._path = path
self._zip_root_dir = None self._zip_root_dir = None
self._zip_file = None self._zip_file = None
self._installation_time = os.stat(path).st_mtime
if not os.path.isdir(self._path): if not os.path.isdir(self._path):
try: try:
@ -155,6 +156,11 @@ class Bundle(object):
"""Get the bundle path.""" """Get the bundle path."""
return self._path return self._path
def get_installation_time(self):
"""Get a timestamp representing the time at which this activity was
installed."""
return self._installation_time
def _unzip(self, install_dir): def _unzip(self, install_dir):
if self._zip_file is None: if self._zip_file is None:
raise AlreadyInstalledException raise AlreadyInstalledException

View File

@ -22,6 +22,7 @@ UNSTABLE.
""" """
from ConfigParser import ConfigParser from ConfigParser import ConfigParser
import tempfile
import os import os
import urllib import urllib
@ -48,15 +49,10 @@ class ContentBundle(Bundle):
Bundle.__init__(self, path) Bundle.__init__(self, path)
self._locale = None self._locale = None
self._l10n = None
self._category = None
self._name = None self._name = None
self._subcategory = None self._icon = None
self._category_class = None
self._category_icon = None
self._library_version = '0' self._library_version = '0'
self._bundle_class = None self._activity_start = 'index.html'
self._activity_start = None
self._global_name = None self._global_name = None
info_file = self.get_file('library/library.info') info_file = self.get_file('library/library.info')
@ -64,11 +60,10 @@ class ContentBundle(Bundle):
raise MalformedBundleException('No library.info file') raise MalformedBundleException('No library.info file')
self._parse_info(info_file) self._parse_info(info_file)
if (self.get_file('index.html') is None and if self.get_file(self._activity_start) is None:
self.get_file('library/library.xml') is None):
raise MalformedBundleException( raise MalformedBundleException(
'Content bundle %s has neither index.html nor library.xml' % 'Content bundle %s does not have start page %s' %
self._path) (self._path, self._activity_start))
def _parse_info(self, info_file): def _parse_info(self, info_file):
cp = ConfigParser() cp = ConfigParser()
@ -92,67 +87,26 @@ class ContentBundle(Bundle):
(self._path, version)) (self._path, version))
self._library_version = version self._library_version = version
if cp.has_option(section, 'l10n'):
l10n = cp.get(section, 'l10n')
if l10n == 'true':
self._l10n = True
elif l10n == 'false':
self._l10n = False
else:
raise MalformedBundleException(
'Content bundle %s has invalid l10n key %r' %
(self._path, l10n))
else:
raise MalformedBundleException(
'Content bundle %s does not specify if it is localized' %
self._path)
if cp.has_option(section, 'locale'): if cp.has_option(section, 'locale'):
self._locale = cp.get(section, 'locale') self._locale = cp.get(section, 'locale')
else:
raise MalformedBundleException(
'Content bundle %s does not specify a locale' % self._path)
if cp.has_option(section, 'category'):
self._category = cp.get(section, 'category')
else:
raise MalformedBundleException(
'Content bundle %s does not specify a category' % self._path)
if cp.has_option(section, 'global_name'): if cp.has_option(section, 'global_name'):
self._global_name = cp.get(section, 'global_name') self._global_name = cp.get(section, 'global_name')
else:
self._global_name = None
if cp.has_option(section, 'category_icon'): if cp.has_option(section, 'icon'):
self._category_icon = cp.get(section, 'category_icon') self._icon = cp.get(section, 'icon')
else:
self._category_icon = None
if cp.has_option(section, 'category_class'): # Compatibility with old content bundles
self._category_class = cp.get(section, 'category_class') if not self._global_name is None \
else: and cp.has_option(section, 'bundle_class'):
self._category_class = None self._global_name = cp.get(section, 'bundle_class')
if cp.has_option(section, 'subcategory'):
self._subcategory = cp.get(section, 'subcategory')
else:
self._subcategory = None
if cp.has_option(section, 'bundle_class'):
self._bundle_class = cp.get(section, 'bundle_class')
else:
self._bundle_class = None
if cp.has_option(section, 'activity_start'): if cp.has_option(section, 'activity_start'):
self._activity_start = cp.get(section, 'activity_start') self._activity_start = cp.get(section, 'activity_start')
else:
self._activity_start = 'index.html'
if self._bundle_class is None and self._global_name is None: if self._global_name is None:
raise MalformedBundleException( raise MalformedBundleException(
'Content bundle %s must specify either global_name or ' 'Content bundle %s must specify global_name' % self._path)
'bundle_class' % self._path)
def get_name(self): def get_name(self):
return self._name return self._name
@ -160,74 +114,53 @@ class ContentBundle(Bundle):
def get_library_version(self): def get_library_version(self):
return self._library_version return self._library_version
def get_l10n(self):
return self._l10n
def get_locale(self): def get_locale(self):
return self._locale return self._locale
def get_category(self):
return self._category
def get_category_icon(self):
return self._category_icon
def get_category_class(self):
return self._category_class
def get_subcategory(self):
return self._subcategory
def get_bundle_class(self):
return self._bundle_class
def get_activity_start(self): def get_activity_start(self):
return self._activity_start return self._activity_start
def get_icon(self): def get_icon(self):
# To be implemented later if not self._icon:
return None return None
def _run_indexer(self): icon_path = os.path.join('library', self._icon)
xdg_data_dirs = os.getenv('XDG_DATA_DIRS', ext = os.path.splitext(icon_path)[1]
'/usr/local/share/:/usr/share/') if ext == '':
for path in xdg_data_dirs.split(':'): ext = '.svg'
indexer = os.path.join(path, 'library-common', 'make_index.py') icon_path += ext
if os.path.exists(indexer):
os.spawnlp(os.P_WAIT, 'python', 'python', indexer)
def get_root_dir(self): if self._zip_file is None:
return os.path.join(env.get_user_library_path(), self._zip_root_dir) return os.path.join(self._path, icon_path)
else:
def get_start_path(self): icon_data = self.get_file(icon_path).read()
return os.path.join(self.get_root_dir(), self._activity_start) temp_file, temp_file_path = tempfile.mkstemp(prefix=self._icon,
suffix=ext)
os.write(temp_file, icon_data)
os.close(temp_file)
return temp_file_path
def get_start_uri(self): def get_start_uri(self):
return 'file://' + urllib.pathname2url(self.get_start_path()) path = os.path.join(self.get_path(), self._activity_start)
return 'file://' + urllib.pathname2url(path)
def get_bundle_id(self): def get_bundle_id(self):
# TODO treat ContentBundle in special way
# needs rethinking while fixing ContentBundle support
if self._bundle_class is not None:
return self._bundle_class
else:
return self._global_name return self._global_name
def get_activity_version(self): def get_activity_version(self):
# TODO treat ContentBundle in special way
# needs rethinking while fixing ContentBundle support
return self._library_version return self._library_version
def get_tags(self):
return None
def install(self): def install(self):
install_path = env.get_user_library_path() install_path = env.get_user_library_path()
self._unzip(install_path) self._unzip(install_path)
self._run_indexer() return os.path.join(install_path, self._zip_root_dir)
return self.get_root_dir()
def uninstall(self, force=False, delete_profile=False): def uninstall(self, force=False, delete_profile=False):
install_dir = self._path install_dir = self._path
self._uninstall(install_dir) self._uninstall(install_dir)
self._run_indexer()
def is_user_activity(self): def is_user_activity(self):
# All content bundles are installed in user storage # All content bundles are installed in user storage