Alon Bar-Lev has uploaded a new change for review.

Change subject: core: add prefix directories to pluin name
......................................................................

core: add prefix directories to pluin name

Change-Id: I9391cff6b74b108e47798431aad6129c1f2ea3f7
Signed-off-by: Alon Bar-Lev <[email protected]>
---
M src/otopi/context.py
1 file changed, 32 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/otopi refs/changes/27/20727/1

diff --git a/src/otopi/context.py b/src/otopi/context.py
index f1814c3..630b98f 100644
--- a/src/otopi/context.py
+++ b/src/otopi/context.py
@@ -70,27 +70,46 @@
         if self.environment[constants.BaseEnv.DEBUG] > 0:
             print(msg)
 
-    def _loadPlugins(self, base, groupname):
+    def _loadPlugins(self, base, path, groupname):
         if (
-            os.path.isdir(base) and
-            os.path.basename(base)[0] not in ('_', '.')
+            os.path.isdir(path) and
+            os.path.basename(path)[0] not in ('_', '.')
         ):
-            if not glob.glob(os.path.join(base, '__init__.py*')):
-                for d in glob.glob(os.path.join(base, '*')):
-                    self._loadPlugins(d, groupname)
+            if not glob.glob(os.path.join(path, '__init__.py*')):
+                for d in glob.glob(os.path.join(path, '*')):
+                    self._loadPlugins(base, d, groupname)
             else:
                 self._earlyDebug(
                     'Loading plugin %s:%s (%s)' % (
                         groupname,
-                        os.path.basename(base),
-                        base,
+                        os.path.basename(path),
+                        path,
                     )
                 )
+
+                def _synth(s):
+                    r = ''
+                    for c in s:
+                        if c in '._' or c.isalnum():
+                            r += c
+                        else:
+                            r += '_'
+                    return r
+
+                prefix = _synth(
+                    os.path.relpath(
+                        os.path.dirname(path),
+                        base
+                    ).replace('/', '.')
+                ).lstrip('.')
+                self._earlyDebug("XXXX !%s!" % prefix)
+
                 util.loadModule(
-                    os.path.dirname(base),
-                    'otopi.plugins.%s.%s' % (
-                        groupname.replace('-', '_'),
-                        os.path.basename(base),
+                    os.path.dirname(path),
+                    'otopi.plugins.%s.%s%s' % (
+                        _synth(groupname),
+                        '%s.' % prefix if prefix else '',
+                        os.path.basename(path),
                     ),
                 ).createPlugins(self)
 
@@ -102,7 +121,7 @@
                 if groupname in needgroups:
                     self._earlyDebug('Loading plugin group %s' % groupname)
                     loadedgroups.append(groupname)
-                    self._loadPlugins(path, groupname)
+                    self._loadPlugins(path, path, groupname)
 
     def _methodName(self, methodinfo):
         method = methodinfo['method']


-- 
To view, visit http://gerrit.ovirt.org/20727
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I9391cff6b74b108e47798431aad6129c1f2ea3f7
Gerrit-PatchSet: 1
Gerrit-Project: otopi
Gerrit-Branch: master
Gerrit-Owner: Alon Bar-Lev <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to