From efdb96ee6584c7d63043fff2f9dcf7552a1ff896 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Thu, 26 Nov 2009 15:45:27 +0000 Subject: Journal entry bundles shouldn't create a 2nd ds entry This fixes a problem where "Show in Journal" from a Browse download was broken. This is because the JEB installation code would extract the content from the bundle entry, install it as a new datastore entry, and then delete the bundle entry. This is fixed by making the journal entry from the bundle take over the datastore entry that belonged to the bundle. --- diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py index bc0ba14..18cc64a 100644 --- a/src/jarabe/journal/journalactivity.py +++ b/src/jarabe/journal/journalactivity.py @@ -279,6 +279,18 @@ class JournalActivity(Window): if registry.is_installed(bundle): logging.debug('_check_for_bundle bundle already installed') return + + if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE: + # JournalEntryBundle code takes over the datastore entry and + # transforms it into the journal entry from the bundle -- we have + # nothing more to do. + try: + registry.install(bundle, metadata['uid']) + except (ZipExtractException, RegistrationException): + logging.exception('Could not install bundle %s', + bundle.get_path()) + return + try: registry.install(bundle) except (ZipExtractException, RegistrationException): @@ -286,10 +298,6 @@ class JournalActivity(Window): (bundle.get_path(), traceback.format_exc())) return - if metadata['mime_type'] == JournalEntryBundle.MIME_TYPE: - model.delete(object_id) - return - metadata['bundle_id'] = bundle.get_bundle_id() model.write(metadata) diff --git a/src/jarabe/journal/journalentrybundle.py b/src/jarabe/journal/journalentrybundle.py index 74b2ac5..9e68c06 100644 --- a/src/jarabe/journal/journalentrybundle.py +++ b/src/jarabe/journal/journalentrybundle.py @@ -40,24 +40,24 @@ class JournalEntryBundle(Bundle): def __init__(self, path): Bundle.__init__(self, path) - def install(self, install_path): + def install(self, install_path, uid=''): if os.environ.has_key('SUGAR_ACTIVITY_ROOT'): install_dir = os.path.join(os.environ['SUGAR_ACTIVITY_ROOT'], 'data') else: install_dir = tempfile.gettempdir() bundle_dir = os.path.join(install_dir, self._zip_root_dir) - uid = self._zip_root_dir + temp_uid = self._zip_root_dir self._unzip(install_dir) try: metadata = self._read_metadata(bundle_dir) - metadata['uid'] = '' + metadata['uid'] = uid - preview = self._read_preview(uid, bundle_dir) + preview = self._read_preview(temp_uid, bundle_dir) if preview is not None: metadata['preview'] = dbus.ByteArray(preview) - file_path = os.path.join(bundle_dir, uid) + file_path = os.path.join(bundle_dir, temp_uid) model.write(metadata, file_path) finally: shutil.rmtree(bundle_dir, ignore_errors=True) diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py index 516c405..ac785fd 100644 --- a/src/jarabe/model/bundleregistry.py +++ b/src/jarabe/model/bundleregistry.py @@ -329,7 +329,7 @@ class BundleRegistry(gobject.GObject): return True return False - def install(self, bundle): + def install(self, bundle, uid=None): activities_path = env.get_user_activities_path() if self.is_pre_installed(bundle.get_bundle_id()) or \ @@ -345,8 +345,11 @@ class BundleRegistry(gobject.GObject): self.uninstall(installed_bundle, force=True) install_dir = env.get_user_activities_path() - install_path = bundle.install(install_dir) - + if isinstance(bundle, JournalEntryBundle): + install_path = bundle.install(install_dir, uid) + else: + install_path = bundle.install(install_dir) + # TODO treat ContentBundle in special way # needs rethinking while fixing ContentBundle support if isinstance(bundle, ContentBundle) or \ -- cgit v0.9.1