Ticket #897: 0002-restore-sugar-launch-by-bundle-id-substring-fixes-89.patch

File 0002-restore-sugar-launch-by-bundle-id-substring-fixes-89.patch, 2.4 KB (added by quozl, 14 years ago)

proposed patch, change to API, adding a feature without impact to existing uses

  • src/jarabe/model/bundleregistry.py

    From 54583f10e2615f6410d0eb330a6be72cc165c2da Mon Sep 17 00:00:00 2001
    From: James Cameron <quozl@laptop.org>
    Date: Tue, 16 Feb 2010 14:54:05 +1100
    Subject: [PATCH 2/2] restore sugar-launch by bundle id substring, fixes #897
    
    sugar-launch uses GetBundlePath which calls bundleregistry.get_bundle().
    
    In this patch, the get_bundle() method is changed to retain as much of
    the original API as possible, yet in the situation where it might return
    None it will now return a bundle if there is only one bundle that
    matches the search string.
    
    http://bugs.sugarlabs.org/ticket/897
    http://dev.laptop.org/ticket/9189
    
    Patch tested on Sugar 0.84.10 on OLPC XO-1.5 build os108.
    
    Test case:
    
    import jarabe.model.bundleregistry
    registry = jarabe.model.bundleregistry.BundleRegistry()
    tests = ['org.laptop.Terminal', 'Terminal', 'terminal', 'e', 'asdqweas']
    for x in tests:
        y = registry.get_bundle(x)
        if y is None:
            z = 'None'
        else:
            z = y.get_bundle_id()
        print x, z
    
    Output before patch:
    
    org.laptop.Terminal org.laptop.Terminal
    Terminal None
    terminal None
    e None
    asdqweas None
    
    Output after patch:
    
    org.laptop.Terminal org.laptop.Terminal
    Terminal org.laptop.Terminal
    terminal org.laptop.Terminal
    e None
    asdqweas None
    ---
     src/jarabe/model/bundleregistry.py |   16 +++++++++++++---
     1 files changed, 13 insertions(+), 3 deletions(-)
    
    diff --git a/src/jarabe/model/bundleregistry.py b/src/jarabe/model/bundleregistry.py
    index 60b2ab9..4e7ef66 100644
    a b class BundleRegistry(gobject.GObject): 
    158158        self._write_favorites_file()
    159159
    160160    def get_bundle(self, bundle_id):
    161         """Returns an bundle given his service name"""
     161        """Returns a bundle given service name or substring,
     162        returns None if there is either no match, or more than one
     163        match by substring."""
     164        result = []
     165        key = bundle_id.lower()
     166
    162167        for bundle in self._bundles:
    163             if bundle.get_bundle_id() == bundle_id:
     168            name = bundle.get_bundle_id()
     169            if name == bundle_id:
    164170                return bundle
     171            if key in name.lower():
     172                result.append(bundle)
     173        if len(result) == 1:
     174            return result[0]
    165175        return None
    166    
     176
    167177    def __iter__(self):
    168178        return self._bundles.__iter__()
    169179