From 02d3799b54c55d7803bc933fab44cb2fde38323e Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Wed, 16 Jul 2008 12:48:31 -0400 Subject: [PATCH] #7532 install + open content bundles through journal --- src/sugar/bundle/contentbundle.py | 24 ++++++++++++++++++++---- src/sugar/datastore/datastore.py | 18 ++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/sugar/bundle/contentbundle.py b/src/sugar/bundle/contentbundle.py index 38d4e513..32f38e30 100644 --- a/src/sugar/bundle/contentbundle.py +++ b/src/sugar/bundle/contentbundle.py @@ -19,6 +19,7 @@ from ConfigParser import ConfigParser import os +import urllib from sugar import env from sugar.bundle.bundle import Bundle, NotInstalledException, \ @@ -140,6 +141,11 @@ class ContentBundle(Bundle): else: self._bundle_class = None + if cp.has_option(section, 'activity_start'): + self._activity_start = cp.get(section, 'activity_start') + else: + self._activity_start = 'index.html' + def get_name(self): return self._name @@ -167,6 +173,9 @@ class ContentBundle(Bundle): def get_bundle_class(self): return self._bundle_class + def get_activity_start(self): + return self._activity_start + def _run_indexer(self): xdg_data_dirs = os.getenv('XDG_DATA_DIRS', '/usr/local/share/:/usr/share/') @@ -175,11 +184,19 @@ class ContentBundle(Bundle): if os.path.exists(indexer): os.spawnlp(os.P_WAIT, 'python', 'python', indexer) + def get_root_dir(self): + return os.path.join(env.get_user_library_path(), self._zip_root_dir) + + def get_start_path(self): + return os.path.join(self.get_root_dir(), self._activity_start) + + def get_start_uri(self): + return "file://" + urllib.pathname2url(self.get_start_path()) + def is_installed(self): if self._unpacked: return True - elif os.path.isdir(os.path.join(env.get_user_library_path(), - self._zip_root_dir)): + elif os.path.isdir(self.get_root_dir()): return True else: return False @@ -194,7 +211,6 @@ class ContentBundle(Bundle): raise NotInstalledException install_dir = self._path else: - install_dir = os.path.join(env.get_user_library_path(), - self._zip_root_dir) + install_dir = os.path.join(self.get_root_dir()) self._uninstall(install_dir) self._run_indexer() diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py index b7792f43..b88a8775 100644 --- a/src/sugar/datastore/datastore.py +++ b/src/sugar/datastore/datastore.py @@ -169,6 +169,24 @@ class DSObject(object): logging.debug('activityfactory.creating bundle with id %r', bundle.get_bundle_id()) activityfactory.create(bundle.get_bundle_id()) + + elif self.is_content_bundle() and not bundle_id: + + logging.debug('Creating content bundle') + bundle = ContentBundle(self.file_path) + if not bundle.is_installed(): + logging.debug('Installing content bundle') + bundle.install() + + activities = self._get_activities_for_mime('text/html') + if len(activities) == 0: + logging.warning('No activity can open HTML content bundles') + return + + uri = bundle.get_start_uri() + logging.debug('activityfactory.creating with uri %s', uri) + activityfactory.create_with_uri(activities[0].bundle_id, + bundle.get_start_uri()) else: if not self.get_activities() and bundle_id is None: logging.warning('No activity can open this object, %s.' %