[Sugar-devel] [PATCH v4 sugar] Downgrading activities not allowed. (#2164)

Aleksey Lim alsroot at member.fsf.org
Sun Oct 17 04:45:06 EDT 2010


On Sun, Oct 17, 2010 at 01:55:00AM +0530, anubhav at seeta.in wrote:
> 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.

So we are in agreement to not use special window for downgrade alert
(we have at least one response from Garry), so downgarade alert
should be just regular alert(alert.py from sugar-toolkit)
in Journal window.

(and you didn't pass your patch though sugar-lint)

> v1 -> v2. Named according to the nomenclature suggested,inline function used,signal emission condition revised,global variables removed.
> 
> v2 -> v3. Taking care of all calling of misc.resume.
> 
> v3 -> v4. Changes in the copyright of the new file
> 
> Signed-off-by: Anubhav Aggarwal <anubhav at seeta.in> , Shanjit Singh Jajmann <shanjit at seeta.in>
> 
> ---
>  src/jarabe/journal/misc.py         |   29 ++++++---
>  src/jarabe/journal/versionalert.py |  122 ++++++++++++++++++++++++++++++++++++
>  src/jarabe/model/bundleregistry.py |    9 ++-
>  3 files changed, 148 insertions(+), 12 deletions(-)
>  create mode 100644 src/jarabe/journal/versionalert.py
> 
> diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py
> index 32a2847..f060bb2 100644
> --- a/src/jarabe/journal/misc.py
> +++ b/src/jarabe/journal/misc.py
> @@ -30,12 +30,14 @@ from sugar.graphics.xocolor import XoColor
>  from sugar import mime
>  from sugar.bundle.activitybundle import ActivityBundle
>  from sugar.bundle.contentbundle import ContentBundle
> +from sugar.bundle.bundle import AlreadyInstalledException
>  from sugar import util
>  
>  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.versionalert import VersionAlert
>  
>  def _get_icon_for_mime(mime_type):
>      generic_types = mime.get_all_generic_types()
> @@ -150,6 +152,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,19 +162,27 @@ 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:
> +                v_alert = VersionAlert()
> +                v_alert.give_bundle(bundle)
> +                version_downgrade= True
> +                logging.debug('done')
> +
>          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:
> +            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())
>  
>      elif is_content_bundle(metadata) and bundle_id is None:
>  
> diff --git a/src/jarabe/journal/versionalert.py b/src/jarabe/journal/versionalert.py
> new file mode 100644
> index 0000000..b0e30b0
> --- /dev/null
> +++ b/src/jarabe/journal/versionalert.py
> @@ -0,0 +1,122 @@
> +#Copyright (C) 2010 Software for Education, Entertainment and Training Activities
> +#
> +# This program is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU General Public License as published by
> +# the Free Software Foundation; either version 2 of the License, or
> +# (at your option) any later version.
> +#
> +# This program is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +# You should have received a copy of the GNU General Public License
> +# along with this program; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
> +
> +import gtk
> +from gettext import gettext as _
> +
> +from sugar.graphics import style
> +from jarabe.model import bundleregistry
> +from sugar.activity import activityfactory
> +import logging
> +
> +class VersionAlert(gtk.Window):
> +
> +    def __init__(self):
> +        gtk.Window.__init__(self)
> +
> +        self.set_border_width(style.LINE_WIDTH)
> +        offset = style.GRID_CELL_SIZE
> +        width = gtk.gdk.screen_width() - offset * 3
> +        height = gtk.gdk.screen_height() - offset * 8.5
> +        self.set_size_request(width, height)
> +        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
> +        self.set_decorated(gtk.WINDOW_TOPLEVEL)
> +        self.set_resizable(False)
> +        self.set_modal(False)
> +        
> +        logging.debug('reached here')
> +        self._main_view = gtk.EventBox()
> +        self._vbox = gtk.VBox()
> +        self._vbox.set_spacing(style.DEFAULT_SPACING)
> +        self._vbox.set_border_width(style.GRID_CELL_SIZE - 30)
> +        self._main_view.modify_bg(gtk.STATE_NORMAL,
> +                                  style.COLOR_BLACK.get_gdk_color())
> +        self._main_view.add(self._vbox)
> +        self._vbox.show()
> +
> +        self._title = gtk.Label()
> +        self._title.modify_fg(gtk.STATE_NORMAL,
> +                              style.COLOR_WHITE.get_gdk_color())
> +        self._title.set_markup('<b>%s</b>' % _('Newer Version of the activity i'
> +                                               's found'))
> +        self._vbox.pack_start(self._title, False)
> +        self._title.show()
> +
> +    	self._message = gtk.Label(_('Do you want to continue with its installat'
> +                                    'ion?'))
> +                                    
> +        self._message.modify_fg(gtk.STATE_NORMAL,
> +                              style.COLOR_WHITE.get_gdk_color())
> +        self._vbox.pack_start(self._message, False)
> +        self._message.show()
> +        
> +        self._hbox = gtk.HBox()
> +        self._hbox.set_spacing(style.DEFAULT_SPACING * 49)
> +       
> +
> +
> +        alignment = gtk.Alignment(xalign=0.5, yalign=0.5)
> +        self._hbox.pack_start(alignment, expand=False)
> +        alignment.show()
> +
> +        self._install_cancel = gtk.Button()
> +        self._install_cancel.set_label(_('Cancel'))
> +        alignment.add(self._install_cancel)
> +        self._install_cancel.show()
> +        self._install_cancel.connect('clicked', self.__install_cancel_cb)
> +
> +
> +        alignment = gtk.Alignment(xalign=0.5, yalign=0.5)
> +        self._hbox.pack_start(alignment, expand=False)
> +        alignment.show()
> +
> +        self._install_ok = gtk.Button()
> +        self._install_ok.set_label(_('  Ok  '))
> +        alignment.add(self._install_ok)
> +        self._install_ok.show()
> +        self._install_ok.connect('clicked', self.__install_ok_cb)
> +        self._vbox.pack_start(self._hbox, False)
> +        self.add(self._main_view)
> +        
> +
> +        self._main_view.show()
> +        self._hbox.show()    
> +        self.connect("realize", self.__realize_cb)
> +        self.show()
> +
> +    def give_bundle(self,bundle):
> +        self.bundle = bundle     
> +
> +    def __realize_cb(self, widget):
> +        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
> +        self.window.set_accept_focus(True)
> +
> +    def __install_cancel_cb(self, button):
> +        '''The opener will listen on the destroy signal
> +        '''
> +        logging.debug('1')
> +        self.destroy()
> + 
> +    def __install_ok_cb(self, button):
> +        logging.debug('2')
> +        registry = bundleregistry.get_registry()
> +        registry.install(self.bundle,uid=None,force_downgrade=True)
> +        installed_bundle = registry.get_bundle(self.bundle.get_bundle_id())
> +        if installed_bundle:
> +            activityfactory.create(installed_bundle)
> +        '''The opener will listen on the destroy signal
> +        '''
> +        self.destroy() 
> diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
> index 699e339..c3f91c3 100644
> --- a/src/jarabe/model/bundleregistry.py
> +++ b/src/jarabe/model/bundleregistry.py
> @@ -373,17 +373,20 @@ 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
> +                else:
> +                    self.uninstall(installed_bundle, force=True)
>              elif bundle.get_bundle_id() == installed_bundle.get_bundle_id():
>                  self.uninstall(installed_bundle, force=True)
> -
> +                    
>          install_dir = env.get_user_activities_path()
>          if isinstance(bundle, JournalEntryBundle):
>              install_path = bundle.install(uid)
> -- 
> 1.7.0.4
> 

-- 
Aleksey


More information about the Sugar-devel mailing list