Ticket #1442: 0001-Reject-activity-bundles-which-require-a-newer-versio.patch

File 0001-Reject-activity-bundles-which-require-a-newer-versio.patch, 1.8 KB (added by wadeb, 15 years ago)
  • src/jarabe/model/bundleregistry.py

    From daae0c6265cf9491097a2a177766f55041fc6b83 Mon Sep 17 00:00:00 2001
    From: Wade Brainerd <wadetb@gmail.com>
    Date: Sun, 27 Sep 2009 20:30:28 -0400
    Subject: [PATCH] Reject activity bundles which require a newer version of Sugar
    
    ---
     src/jarabe/model/bundleregistry.py |   21 +++++++++++++++++++++
     1 files changed, 21 insertions(+), 0 deletions(-)
    
    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index b754952..77c9416 100644
    a b class BundleRegistry(gobject.GObject): 
    209209        else:
    210210            return False
    211211
     212    def _compare_versions(self, a, b):
     213        """Return True if version a is newer than version b
     214       
     215        Both a and b must be in the form x.y.z"""
     216       
     217        a_list = a.split('.')
     218        b_list = b.split('.')
     219
     220        for i in range(len(a_list)):
     221            if int(a_list[i]) > int(b_list[i]):
     222                return True
     223            elif int(a_list[i]) < int(b_list[i]):
     224                return False
     225        return False
     226
    212227    def _add_bundle(self, bundle_path, install_mime_type=False):
    213228        logging.debug('STARTUP: Adding bundle %r', bundle_path)
    214229        try:
    class BundleRegistry(gobject.GObject): 
    219234            logging.exception('Error loading bundle %r', bundle_path)
    220235            return None
    221236
     237        # Compare version strings.
     238        if self._compare_versions(bundle.get_sugar_version(), config.version):
     239            logging.exception('Bundle %r requires Sugar version %s or newer' %
     240                              (bundle_path, bundle.get_sugar_version()))
     241            return None
     242
    222243        bundle_id = bundle.get_bundle_id()
    223244        installed = self.get_bundle(bundle_id)
    224245