[FIX] cli: allows multiple addons path: --addons-path=path1,path2 , path3
authorJulien Thewys <jth@openerp.com>
Sat, 30 Apr 2011 15:25:05 +0000 (17:25 +0200)
committerJulien Thewys <jth@openerp.com>
Sat, 30 Apr 2011 15:25:05 +0000 (17:25 +0200)
This was only possible in the config file.

lp bug: https://launchpad.net/bugs/507973 fixed

bzr revid: jth@openerp.com-20110430152505-t57u24s2a1am3bjh

bin/tools/config.py

index 6ff7935..9655395 100644 (file)
@@ -412,26 +412,28 @@ class configmanager(object):
             import stat
             os.chmod(filename, stat.S_IRUSR + stat.S_IWUSR)
 
-    def _check_addons_path(self, option, opt, value, parser):
-        res = os.path.abspath(os.path.expanduser(value))
-        if not os.path.exists(res):
-            raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, value))
-
-        contains_addons = False
-        for f in os.listdir(res):
-            modpath = os.path.join(res, f)
-            if os.path.isdir(modpath) and \
-               os.path.exists(os.path.join(modpath, '__init__.py')) and \
-               (os.path.exists(os.path.join(modpath, '__openerp__.py')) or \
-                os.path.exists(os.path.join(modpath, '__terp__.py'))):
-
-                contains_addons = True
-                break
-
-        if not contains_addons:
-            raise optparse.OptionValueError("option %s: The addons-path %r does not seem to a be a valid Addons Directory!" % (opt, value))
+    def _is_addons_path(self, path):
+        for f in os.listdir(path):
+            modpath = os.path.join(path, f)
+            if os.path.isdir(modpath):
+                def hasfile(filename):
+                    return os.path.isfile(os.path.join(modpath, filename))
+                if hasfile('__init__.py') and (hasfile('__openerp__.py') or hasfile('__terp__.py')):
+                    return True
+        return False
 
-        setattr(parser.values, option.dest, res)
+    def _check_addons_path(self, option, opt, value, parser):
+        ad_paths = []
+        for path in value.split(','):
+            path = path.strip()
+            res = os.path.abspath(os.path.expanduser(path))
+            if not os.path.isdir(res):
+                raise optparse.OptionValueError("option %s: no such directory: %r" % (opt, path))
+            if not self._is_addons_path(res):
+                raise optparse.OptionValueError("option %s: The addons-path %r does not seem to a be a valid Addons Directory!" % (opt, path))
+            ad_paths.append(res)
+
+        setattr(parser.values, option.dest, ",".join(ad_paths))
 
     def load(self):
         p = ConfigParser.ConfigParser()