Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorDan Winship <dwinship@redhat.com>2007-08-16 14:36:20 (GMT)
committer Dan Winship <dwinship@redhat.com>2007-08-16 14:36:20 (GMT)
commitf876a63b0b984e80e15b786b10d95ae9c69db603 (patch)
treefb09bc97b653ddbeaa71b03c5c748a3a43b3d2ef /services
parent4ad4fe9ec8caf64f99714bbc63435d4ffbc5bb8d (diff)
Sort the activities by mtime to ensure a stable ordering. Part of #2716
Diffstat (limited to 'services')
-rw-r--r--services/shell/bundleregistry.py38
1 files changed, 24 insertions, 14 deletions
diff --git a/services/shell/bundleregistry.py b/services/shell/bundleregistry.py
index 65a2348..19d0032 100644
--- a/services/shell/bundleregistry.py
+++ b/services/shell/bundleregistry.py
@@ -69,16 +69,16 @@ class BundleRegistry(gobject.GObject):
def __init__(self):
gobject.GObject.__init__(self)
- self._bundles = {}
+ self._bundles = []
self._search_path = []
self._service_manager = _ServiceManager()
def get_bundle(self, service_name):
"""Returns an bundle given his service name"""
- if self._bundles.has_key(service_name):
- return self._bundles[service_name]
- else:
- return None
+ for bundle in self._bundles:
+ if bundle.get_service_name() == service_name:
+ return bundle
+ return None
def add_search_path(self, path):
"""Add a directory to the bundles search path"""
@@ -86,20 +86,30 @@ class BundleRegistry(gobject.GObject):
self._scan_directory(path)
def __iter__(self):
- return self._bundles.values().__iter__()
+ return self._bundles.__iter__()
def _scan_directory(self, path):
- if os.path.isdir(path):
- for f in os.listdir(path):
- bundle_dir = os.path.join(path, f)
- if os.path.isdir(bundle_dir) and \
- bundle_dir.endswith('.activity'):
- self.add_bundle(bundle_dir)
+ if not os.path.isdir(path):
+ return
+
+ # Sort by mtime to ensure a stable activity order
+ bundles = {}
+ for f in os.listdir(path):
+ if not f.endswith('.activity'):
+ continue
+ bundle_dir = os.path.join(path, f)
+ if os.path.isdir(bundle_dir):
+ bundles[bundle_dir] = os.stat(bundle_dir).st_mtime
+
+ bundle_dirs = bundles.keys()
+ bundle_dirs.sort(lambda d1,d2: cmp(bundles[d1], bundles[d2]))
+ for dir in bundle_dirs:
+ self.add_bundle(dir)
def add_bundle(self, bundle_path):
bundle = Bundle(bundle_path)
if bundle.is_valid():
- self._bundles[bundle.get_service_name()] = bundle
+ self._bundles.append(bundle)
self._service_manager.add(bundle)
self.emit('bundle-added', bundle)
return True
@@ -108,7 +118,7 @@ class BundleRegistry(gobject.GObject):
def get_activities_for_type(self, mime_type):
result = []
- for bundle in self._bundles.values():
+ for bundle in self._bundles:
if bundle.get_mime_types() and mime_type in bundle.get_mime_types():
result.append(bundle)
return result