xmartinez - r8534 - in flumotion/trunk: . flumotion/common

flumotion-commit at lists.fluendo.com flumotion-commit at lists.fluendo.com
Mon Apr 26 10:14:50 CEST 2010


Author: xmartinez
Date: Mon Apr 26 10:14:49 2010
New Revision: 8534

Log:
	reviewed by: Jan Urbanski
	* flumotion/common/registry.py:
	Add paths, prefix, and cachePath keyword args to
	ComponentRegistry.__init__().
	This decouples ComponentRegistry initialization from the
	environment (configure and FLU_PROJECT_PATH), increasing its
	testability.



Modified:
   flumotion/trunk/ChangeLog
   flumotion/trunk/flumotion/common/registry.py

Modified: flumotion/trunk/ChangeLog
==============================================================================
--- flumotion/trunk/ChangeLog	(original)
+++ flumotion/trunk/ChangeLog	Mon Apr 26 10:14:49 2010
@@ -1,3 +1,15 @@
+2010-04-26  Xavier Martinez-Hidalgo  <xmartinez at flumotion.com>
+
+	reviewed by: Jan Urbanski
+
+	* flumotion/common/registry.py:
+	Add paths, prefix, and cachePath keyword args to
+	ComponentRegistry.__init__().
+
+	This decouples ComponentRegistry initialization from the
+	environment (configure and FLU_PROJECT_PATH), increasing its
+	testability.
+
 2010-04-15  Thomas Vander Stichele  <thomas at apestaart dot org>
 
 	* flumotion.spec.in:

Modified: flumotion/trunk/flumotion/common/registry.py
==============================================================================
--- flumotion/trunk/flumotion/common/registry.py	(original)
+++ flumotion/trunk/flumotion/common/registry.py	Mon Apr 26 10:14:49 2010
@@ -1511,9 +1511,17 @@
     """Registry, this is normally not instantiated."""
 
     logCategory = 'registry'
-    filename = os.path.join(configure.registrydir, 'registry.xml')
+    defaultCachePath = os.path.join(configure.registrydir, 'registry.xml')
+
+    def __init__(self, paths=None, prefix=configure.PACKAGE,
+                 cachePath=defaultCachePath):
+        if paths is not None:
+            self._paths = paths
+        else:
+            self._paths = self._getRegistryPathsFromEnviron()
+        self.prefix = prefix
+        self.filename = cachePath
 
-    def __init__(self):
         self._parser = RegistryParser()
 
         if (READ_CACHE and
@@ -1549,17 +1557,20 @@
         self.addFile(f)
         f.close()
 
-    def addRegistryPath(self, path, prefix=configure.PACKAGE):
+    def addRegistryPath(self, path, prefix=None):
         """
         Add a registry path to this registry, scanning it for registry
         snippets.
 
-        @param path: a full path containing a 'flumotion' directory,
-                     which will be scanned for registry files.
+        @param path: a full path containing a PREFIX directory, which will be
+                     scanned for registry files.
+        @param prefix: directory name under path which will be scanned
+                     (defaults to 'flumotion' and cannot be an empty string).
 
         @rtype:   bool
         @returns: whether the path could be added
         """
+        prefix = prefix or self.prefix
         self.debug('path %s, prefix %s' % (path, prefix))
         if not os.path.exists(path):
             self.warning(
@@ -1696,7 +1707,7 @@
 
         # A bit complicated because we want to allow FLU_PROJECT_PATH to
         # point to nonexistent directories
-        registryPaths = python.set(self._getRegistryPathsFromEnviron())
+        registryPaths = python.set(self._paths)
         oldRegistryPaths = python.set([directory.getPath()
                                 for directory in self.getDirectories()])
         if registryPaths != oldRegistryPaths:
@@ -1763,7 +1774,7 @@
             if self.rebuildNeeded():
                 self.info("Rebuild of registry is needed")
             self.clean()
-            for path in self._getRegistryPathsFromEnviron():
+            for path in self._paths:
                 if not self.addRegistryPath(path):
                     self._parser.removeDirectoryByPath(path)
             self.save(True)


More information about the flumotion-commit mailing list