Advertisement
Guest User

Untitled

a guest
Oct 24th, 2010
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. From 169c3d8a89f5eafb12b40b228182654422637a49 Mon Sep 17 00:00:00 2001
  2. From: Shanjit Singh Jajmann <shanjit@seeta.in>
  3. Date: Mon, 25 Oct 2010 00:29:08 +0530
  4. Subject: [PATCH v7] Downgrading activities not allowed. (SL #2164)
  5.  
  6. Activity can be downgraded on the availability of an older .xo version of an
  7. activity. An alert pops up when trying to install an older .xo file of an
  8. activity, which asks the user to make a selection on whether to move to an
  9. older activity version or not.
  10.  
  11. Co-authored-by: Anubhav Aggarwal <anubhav@seeta.in>, Shanjit Singh Jajmann <shanjit@seeta.in>
  12. ---
  13.  
  14. v1 -> v2. Inline function used, signal emission condition revised and global
  15. variables removed. Recommendations by James Cameron and Aleksey Lim added.
  16.  
  17. v2 -> v3. Used misc.resume.
  18.  
  19. v3 -> v4. Changes in the copyright of the new file.
  20.  
  21. v4 -> v5. Alert shown in the same window as the journal.
  22.  
  23. v5 -> v6. Static variable removed, name of the functions changed.
  24. Recommendations by James Cameron and Aleksey Lim added.
  25.  
  26. v6 -> v7. Popping up logic made simpler.
  27. Recommendations by Aleksay Lim added.
  28. ---
  29. src/jarabe/journal/journalactivity.py | 5 ++-
  30. src/jarabe/journal/misc.py | 54 ++++++++++++++++++++++++++------
  31. src/jarabe/model/bundleregistry.py | 7 +++-
  32. 3 files changed, 52 insertions(+), 14 deletions(-)
  33.  
  34. diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
  35. index 44cc018..beb0962 100644
  36. --- a/src/jarabe/journal/journalactivity.py
  37. +++ b/src/jarabe/journal/journalactivity.py
  38. @@ -44,6 +44,7 @@ from jarabe.journal.journalentrybundle import JournalEntryBundle
  39. from jarabe.journal.objectchooser import ObjectChooser
  40. from jarabe.journal.modalalert import ModalAlert
  41. from jarabe.journal import model
  42. +from jarabe.journal.journalwindow import JournalWindow
  43.  
  44. J_DBUS_SERVICE = 'org.laptop.Journal'
  45. J_DBUS_INTERFACE = 'org.laptop.Journal'
  46. @@ -102,10 +103,10 @@ class JournalActivityDBusService(dbus.service.Object):
  47. def ObjectChooserCancelled(self, chooser_id):
  48. pass
  49.  
  50. -class JournalActivity(Window):
  51. +class JournalActivity(JournalWindow):
  52. def __init__(self):
  53. logging.debug("STARTUP: Loading the journal")
  54. - Window.__init__(self)
  55. + JournalWindow.__init__(self)
  56.  
  57. self.set_title(_('Journal'))
  58.  
  59. diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
  60. index 32a2847..54b525e 100644
  61. --- a/src/jarabe/journal/misc.py
  62. +++ b/src/jarabe/journal/misc.py
  63. @@ -27,8 +27,10 @@ from sugar.activity import activityfactory
  64. from sugar.activity.activityhandle import ActivityHandle
  65. from sugar.graphics.icon import get_icon_file_name
  66. from sugar.graphics.xocolor import XoColor
  67. +from sugar.graphics.alert import ConfirmationAlert
  68. from sugar import mime
  69. from sugar.bundle.activitybundle import ActivityBundle
  70. +from sugar.bundle.bundle import AlreadyInstalledException
  71. from sugar.bundle.contentbundle import ContentBundle
  72. from sugar import util
  73.  
  74. @@ -36,6 +38,7 @@ from jarabe.view import launcher
  75. from jarabe.model import bundleregistry, shell
  76. from jarabe.journal.journalentrybundle import JournalEntryBundle
  77. from jarabe.journal import model
  78. +from jarabe.journal import journalwindow
  79.  
  80. def _get_icon_for_mime(mime_type):
  81. generic_types = mime.get_all_generic_types()
  82. @@ -150,6 +153,7 @@ def get_activities(metadata):
  83.  
  84. def resume(metadata, bundle_id=None):
  85. registry = bundleregistry.get_registry()
  86. + version_downgrade = False
  87.  
  88. if is_activity_bundle(metadata) and bundle_id is None:
  89.  
  90. @@ -159,20 +163,18 @@ def resume(metadata, bundle_id=None):
  91. bundle = ActivityBundle(file_path)
  92. if not registry.is_installed(bundle):
  93. logging.debug('Installing activity bundle')
  94. - registry.install(bundle)
  95. + try:
  96. + registry.install(bundle)
  97. + except AlreadyInstalledException:
  98. + _downgrade_option_alert(bundle)
  99. + version_downgrade = True
  100. else:
  101. logging.debug('Upgrading activity bundle')
  102. registry.upgrade(bundle)
  103.  
  104. - logging.debug('activityfactory.creating bundle with id %r',
  105. - bundle.get_bundle_id())
  106. - installed_bundle = registry.get_bundle(bundle.get_bundle_id())
  107. - if installed_bundle:
  108. - launch(installed_bundle)
  109. - else:
  110. - logging.error('Bundle %r is not installed.',
  111. - bundle.get_bundle_id())
  112. -
  113. + if not version_downgrade:
  114. + _install_bundle(bundle)
  115. +
  116. elif is_content_bundle(metadata) and bundle_id is None:
  117.  
  118. logging.debug('Creating content bundle')
  119. @@ -215,6 +217,21 @@ def resume(metadata, bundle_id=None):
  120. launch(bundle, activity_id=activity_id, object_id=object_id,
  121. color=get_icon_color(metadata))
  122.  
  123. +def _install_bundle(bundle):
  124. + registry = bundleregistry.get_registry()
  125. + logging.debug('activityfactory.creating bundle with id %r',
  126. + bundle.get_bundle_id())
  127. + installed_bundle = registry.get_bundle(bundle.get_bundle_id())
  128. + if installed_bundle:
  129. + launch(installed_bundle)
  130. + else:
  131. + logging.error('Bundle %r is not installed.',
  132. + bundle.get_bundle_id())
  133. +
  134. +def _downgrade_install_bundle(bundle):
  135. + registry = bundleregistry.get_registry()
  136. + registry.install(bundle, force_downgrade=True)
  137. +
  138. def launch(bundle, activity_id=None, object_id=None, uri=None, color=None,
  139. invited=False):
  140. if activity_id is None or not activity_id:
  141. @@ -239,6 +256,23 @@ def launch(bundle, activity_id=None, object_id=None, uri=None, color=None,
  142. object_id=object_id, uri=uri, invited=invited)
  143. activityfactory.create(bundle, activity_handle)
  144.  
  145. +def _downgrade_option_alert(bundle):
  146. + alert = ConfirmationAlert()
  147. + alert.props.title = _('Older Version Of %s Activity') % (bundle.get_name())
  148. + alert.props.msg = _('Do you want to downgrade to version \
  149. + %s') % (bundle.get_activity_version())
  150. + alert.connect('response', _downgrade_alert_response_cb, bundle)
  151. + journalwindow.get_journal_window().add_alert(alert)
  152. + alert.show()
  153. +
  154. +def _downgrade_alert_response_cb(alert, response_id, bundle):
  155. + if response_id is gtk.RESPONSE_OK:
  156. + journalwindow.get_journal_window().remove_alert(alert)
  157. + _downgrade_install_bundle(bundle)
  158. + _install_bundle(bundle)
  159. + elif response_id is gtk.RESPONSE_CANCEL:
  160. + journalwindow.get_journal_window().remove_alert(alert)
  161. +
  162. def is_activity_bundle(metadata):
  163. mime_type = metadata.get('mime_type', '')
  164. return mime_type == ActivityBundle.MIME_TYPE or \
  165. diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
  166. index 699e339..06a1d3a 100644
  167. --- a/src/jarabe/model/bundleregistry.py
  168. +++ b/src/jarabe/model/bundleregistry.py
  169. @@ -373,14 +373,17 @@ class BundleRegistry(gobject.GObject):
  170. return True
  171. return False
  172.  
  173. - def install(self, bundle, uid=None):
  174. + def install(self, bundle, uid=None, force_downgrade=False):
  175. activities_path = env.get_user_activities_path()
  176.  
  177. for installed_bundle in self._bundles:
  178. if bundle.get_bundle_id() == installed_bundle.get_bundle_id() and \
  179. bundle.get_activity_version() <= \
  180. installed_bundle.get_activity_version():
  181. - raise AlreadyInstalledException
  182. + if not force_downgrade:
  183. + raise AlreadyInstalledException
  184. + if force_downgrade:
  185. + self.uninstall(installed_bundle, force=True)
  186. elif bundle.get_bundle_id() == installed_bundle.get_bundle_id():
  187. self.uninstall(installed_bundle, force=True)
  188.  
  189. --
  190. 1.7.2.2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement