#7532 install + open content bundles through journal

This commit is contained in:
Daniel Drake 2008-07-16 12:48:31 -04:00
parent 5d5f75f7e3
commit 02d3799b54
2 changed files with 38 additions and 4 deletions

View File

@ -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()

View File

@ -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.' %