[Dextrose] [PATCH] Downgrading activities not allowed. (#2164)

shanjit at seeta.in shanjit at seeta.in
Wed Oct 13 09:58:51 EDT 2010


Downgrading an activity is now made possible. When a .xo file of a version older than the currently installed version is clicked, a downgrading option is made available, by popping up of a confirmation alert. Depending upton the choice selected you can downgrade the activity.

v1 -> v2. Named according to the nomenclature suggested,inline function used,signal emission condition revised,global variables removed.

Signed-off-by: Shanjit Singh Jajmann <shanjit at seeta.in>, Anubhav Aggarwal <anubhav at seeta.in>
---
 src/jarabe/journal/journalactivity.py |   15 +++++++++++++++
 src/jarabe/journal/listview.py        |   22 ++++++++++++++++++----
 src/jarabe/journal/misc.py            |    8 +++++---
 src/jarabe/model/bundleregistry.py    |   11 ++++++-----
 4 files changed, 44 insertions(+), 12 deletions(-)

diff --git a/src/jarabe/journal/journalactivity.py b/src/jarabe/journal/journalactivity.py
index 44cc018..d0af20a 100644
--- a/src/jarabe/journal/journalactivity.py
+++ b/src/jarabe/journal/journalactivity.py
@@ -28,6 +28,7 @@ import os
 
 from sugar.graphics.window import Window
 from sugar.graphics.alert import ErrorAlert
+from sugar.graphics.alert import ConfirmationAlert
 
 from sugar.bundle.bundle import ZipExtractException, RegistrationException
 from sugar import env
@@ -166,6 +167,7 @@ class JournalActivity(Window):
         self._list_view = ListView()
         self._list_view.connect('detail-clicked', self.__detail_clicked_cb)
         self._list_view.connect('clear-clicked', self.__clear_clicked_cb)
+        self._list_view.connect('older-version-clicked', self.__older_version_clicked_cb)
         self._main_view.pack_start(self._list_view)
         self._list_view.show()
 
@@ -204,6 +206,19 @@ class JournalActivity(Window):
 
     def __go_back_clicked_cb(self, detail_view):
         self.show_main_view()
+    def __older_version_clicked_cb(self,a):
+        alert1=ConfirmationAlert()
+        alert1.props.title = _('Newer Version Found')
+        alert1.props.msg = _('Newer version of the chosen activity is available do you still want to continue with the installation?                                                                              If Yes click Ok and the activity icon of the older .xo file in the Journal')
+        alert1.connect('response',self.__downgrade_alert_response_cb)
+        self.add_alert(alert1)
+        alert1.show()
+    def __downgrade_alert_response_cb(self, alert1, response_id):
+        if response_id is gtk.RESPONSE_OK:
+            self.remove_alert(alert1)
+            self._list_view.downgrade_confirmation()
+        elif response_id is gtk.RESPONSE_CANCEL:
+            self.remove_alert(alert1)
 
     def _query_changed_cb(self, toolbar, query):
         self._list_view.update_with_query(query)
diff --git a/src/jarabe/journal/listview.py b/src/jarabe/journal/listview.py
index 3d6281a..653f400 100644
--- a/src/jarabe/journal/listview.py
+++ b/src/jarabe/journal/listview.py
@@ -27,6 +27,7 @@ import pango
 from sugar.graphics import style
 from sugar.graphics.icon import CanvasIcon, Icon, CellRendererIcon
 from sugar.graphics.xocolor import XoColor
+from sugar.bundle.bundle import AlreadyInstalledException
 from sugar import util
 
 from jarabe.journal.listmodel import ListModel
@@ -466,12 +467,17 @@ class ListView(BaseListView):
     __gsignals__ = {
         'detail-clicked': (gobject.SIGNAL_RUN_FIRST,
                            gobject.TYPE_NONE,
-                           ([object]))
+                           ([object])),
+        'older-version-clicked': (gobject.SIGNAL_RUN_FIRST,
+                                  gobject.TYPE_NONE,
+                                  ([]))
     }
+    
 
     def __init__(self):
         BaseListView.__init__(self)
         self._is_dragging = False
+        self.downgrade = False
 
         self.tree_view.connect('drag-begin', self.__drag_begin_cb)
         self.tree_view.connect('button-release-event',
@@ -522,12 +528,20 @@ class ListView(BaseListView):
 
     def __detail_clicked_cb(self, cell, uid):
         self.emit('detail-clicked', uid)
-
+    def downgrade_confirmation(self):
+        self.downgrade = True
     def __icon_clicked_cb(self, cell, path):
         row = self.tree_view.get_model()[path]
         metadata = model.get(row[ListModel.COLUMN_UID])
-        misc.resume(metadata)
-
+        if not self.downgrade:
+            try:
+                misc.resume(metadata)
+            except AlreadyInstalledException :
+                self.emit('older-version-clicked')
+        if self.downgrade:
+            self.downgrade = False
+            misc.resume(metadata,forcing_downgrade=True)
+ 
     def __cell_title_edited_cb(self, cell, path, new_text):
         row = self._model[path]
         metadata = model.get(row[ListModel.COLUMN_UID])
diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
index 32a2847..0ae4a1d 100644
--- a/src/jarabe/journal/misc.py
+++ b/src/jarabe/journal/misc.py
@@ -148,7 +148,7 @@ def get_activities(metadata):
 
     return activities
 
-def resume(metadata, bundle_id=None):
+def resume(metadata, bundle_id=None,forcing_downgrade = False):
     registry = bundleregistry.get_registry()
 
     if is_activity_bundle(metadata) and bundle_id is None:
@@ -157,15 +157,17 @@ def resume(metadata, bundle_id=None):
 
         file_path = model.get_file(metadata['uid'])
         bundle = ActivityBundle(file_path)
-        if not registry.is_installed(bundle):
+        if (not registry.is_installed(bundle)) and (not forcing_downgrade) :
             logging.debug('Installing activity bundle')
-            registry.install(bundle)
+            registry.install(bundle,uid=None,force_downgrade=False)
+        elif (not registry.is_installed(bundle)) and forcing_downgrade :
+            registry.install(bundle,uid=None,force_downgrade=True)
         else:
             logging.debug('Upgrading activity bundle')
             registry.upgrade(bundle)

diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
index 699e339..ca7948c 100644
--- a/src/jarabe/model/bundleregistry.py
+++ b/src/jarabe/model/bundleregistry.py
@@ -373,14 +373,15 @@ 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 bundle.get_bundle_id() == installed_bundle.get_bundle_id() and bundle.get_activity_version() <= installed_bundle.get_activity_version():
+                if not force_downgrade:
+                    raise AlreadyInstalledException
+                else:
+                    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



More information about the Dextrose mailing list