Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- From 169c3d8a89f5eafb12b40b228182654422637a49 Mon Sep 17 00:00:00 2001
- From: Shanjit Singh Jajmann <shanjit@seeta.in>
- Date: Mon, 25 Oct 2010 00:29:08 +0530
- Subject: [PATCH v7] Downgrading activities not allowed. (SL #2164)
- Activity can be downgraded on the availability of an older .xo version of an
- activity. An alert pops up when trying to install an older .xo file of an
- activity, which asks the user to make a selection on whether to move to an
- older activity version or not.
- Co-authored-by: Anubhav Aggarwal <anubhav@seeta.in>, Shanjit Singh Jajmann <shanjit@seeta.in>
- ---
- v1 -> v2. Inline function used, signal emission condition revised and global
- variables removed. Recommendations by James Cameron and Aleksey Lim added.
- v2 -> v3. Used misc.resume.
- v3 -> v4. Changes in the copyright of the new file.
- v4 -> v5. Alert shown in the same window as the journal.
- v5 -> v6. Static variable removed, name of the functions changed.
- Recommendations by James Cameron and Aleksey Lim added.
- v6 -> v7. Popping up logic made simpler.
- Recommendations by Aleksay Lim added.
- ---
- src/jarabe/journal/journalactivity.py | 5 ++-
- src/jarabe/journal/misc.py | 54 ++++++++++++++++++++++++++------
- src/jarabe/model/bundleregistry.py | 7 +++-
- 3 files changed, 52 insertions(+), 14 deletions(-)
- diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
- index 44cc018..beb0962 100644
- --- a/src/jarabe/journal/journalactivity.py
- +++ b/src/jarabe/journal/journalactivity.py
- @@ -44,6 +44,7 @@ from jarabe.journal.journalentrybundle import JournalEntryBundle
- from jarabe.journal.objectchooser import ObjectChooser
- from jarabe.journal.modalalert import ModalAlert
- from jarabe.journal import model
- +from jarabe.journal.journalwindow import JournalWindow
- J_DBUS_SERVICE = 'org.laptop.Journal'
- J_DBUS_INTERFACE = 'org.laptop.Journal'
- @@ -102,10 +103,10 @@ class JournalActivityDBusService(dbus.service.Object):
- def ObjectChooserCancelled(self, chooser_id):
- pass
- -class JournalActivity(Window):
- +class JournalActivity(JournalWindow):
- def __init__(self):
- logging.debug("STARTUP: Loading the journal")
- - Window.__init__(self)
- + JournalWindow.__init__(self)
- self.set_title(_('Journal'))
- diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
- index 32a2847..54b525e 100644
- --- a/src/jarabe/journal/misc.py
- +++ b/src/jarabe/journal/misc.py
- @@ -27,8 +27,10 @@ from sugar.activity import activityfactory
- from sugar.activity.activityhandle import ActivityHandle
- from sugar.graphics.icon import get_icon_file_name
- from sugar.graphics.xocolor import XoColor
- +from sugar.graphics.alert import ConfirmationAlert
- from sugar import mime
- from sugar.bundle.activitybundle import ActivityBundle
- +from sugar.bundle.bundle import AlreadyInstalledException
- from sugar.bundle.contentbundle import ContentBundle
- from sugar import util
- @@ -36,6 +38,7 @@ from jarabe.view import launcher
- from jarabe.model import bundleregistry, shell
- from jarabe.journal.journalentrybundle import JournalEntryBundle
- from jarabe.journal import model
- +from jarabe.journal import journalwindow
- def _get_icon_for_mime(mime_type):
- generic_types = mime.get_all_generic_types()
- @@ -150,6 +153,7 @@ def get_activities(metadata):
- def resume(metadata, bundle_id=None):
- registry = bundleregistry.get_registry()
- + version_downgrade = False
- if is_activity_bundle(metadata) and bundle_id is None:
- @@ -159,20 +163,18 @@ def resume(metadata, bundle_id=None):
- bundle = ActivityBundle(file_path)
- if not registry.is_installed(bundle):
- logging.debug('Installing activity bundle')
- - registry.install(bundle)
- + try:
- + registry.install(bundle)
- + except AlreadyInstalledException:
- + _downgrade_option_alert(bundle)
- + version_downgrade = True
- else:
- logging.debug('Upgrading activity bundle')
- registry.upgrade(bundle)
- - logging.debug('activityfactory.creating bundle with id %r',
- - bundle.get_bundle_id())
- - installed_bundle = registry.get_bundle(bundle.get_bundle_id())
- - if installed_bundle:
- - launch(installed_bundle)
- - else:
- - logging.error('Bundle %r is not installed.',
- - bundle.get_bundle_id())
- -
- + if not version_downgrade:
- + _install_bundle(bundle)
- +
- elif is_content_bundle(metadata) and bundle_id is None:
- logging.debug('Creating content bundle')
- @@ -215,6 +217,21 @@ def resume(metadata, bundle_id=None):
- launch(bundle, activity_id=activity_id, object_id=object_id,
- color=get_icon_color(metadata))
- +def _install_bundle(bundle):
- + registry = bundleregistry.get_registry()
- + logging.debug('activityfactory.creating bundle with id %r',
- + bundle.get_bundle_id())
- + installed_bundle = registry.get_bundle(bundle.get_bundle_id())
- + if installed_bundle:
- + launch(installed_bundle)
- + else:
- + logging.error('Bundle %r is not installed.',
- + bundle.get_bundle_id())
- +
- +def _downgrade_install_bundle(bundle):
- + registry = bundleregistry.get_registry()
- + registry.install(bundle, force_downgrade=True)
- +
- def launch(bundle, activity_id=None, object_id=None, uri=None, color=None,
- invited=False):
- if activity_id is None or not activity_id:
- @@ -239,6 +256,23 @@ def launch(bundle, activity_id=None, object_id=None, uri=None, color=None,
- object_id=object_id, uri=uri, invited=invited)
- activityfactory.create(bundle, activity_handle)
- +def _downgrade_option_alert(bundle):
- + alert = ConfirmationAlert()
- + alert.props.title = _('Older Version Of %s Activity') % (bundle.get_name())
- + alert.props.msg = _('Do you want to downgrade to version \
- + %s') % (bundle.get_activity_version())
- + alert.connect('response', _downgrade_alert_response_cb, bundle)
- + journalwindow.get_journal_window().add_alert(alert)
- + alert.show()
- +
- +def _downgrade_alert_response_cb(alert, response_id, bundle):
- + if response_id is gtk.RESPONSE_OK:
- + journalwindow.get_journal_window().remove_alert(alert)
- + _downgrade_install_bundle(bundle)
- + _install_bundle(bundle)
- + elif response_id is gtk.RESPONSE_CANCEL:
- + journalwindow.get_journal_window().remove_alert(alert)
- +
- def is_activity_bundle(metadata):
- mime_type = metadata.get('mime_type', '')
- return mime_type == ActivityBundle.MIME_TYPE or \
- diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
- index 699e339..06a1d3a 100644
- --- a/src/jarabe/model/bundleregistry.py
- +++ b/src/jarabe/model/bundleregistry.py
- @@ -373,14 +373,17 @@ class BundleRegistry(gobject.GObject):
- return True
- return False
- - def install(self, bundle, uid=None):
- + def install(self, bundle, uid=None, force_downgrade=False):
- activities_path = env.get_user_activities_path()
- for installed_bundle in self._bundles:
- if bundle.get_bundle_id() == installed_bundle.get_bundle_id() and \
- bundle.get_activity_version() <= \
- installed_bundle.get_activity_version():
- - raise AlreadyInstalledException
- + if not force_downgrade:
- + raise AlreadyInstalledException
- + if force_downgrade:
- + self.uninstall(installed_bundle, force=True)
- elif bundle.get_bundle_id() == installed_bundle.get_bundle_id():
- self.uninstall(installed_bundle, force=True)
- --
- 1.7.2.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement