Adding support for subsystems in PluginManager
authorFrederic Massart <fred@moodle.com>
Fri, 9 May 2014 07:46:00 +0000 (15:46 +0800)
committerFrederic Massart <fred@moodle.com>
Fri, 9 May 2014 07:46:00 +0000 (15:46 +0800)
Yup, it should not really have been mixed up with plugins,
but I am sort of lazy to write 'component' library so
it will be there for now, and I am sure we will live with it.

Also, why the hell did I make that class with only static
methods? I must have had a reason at the time...

lib/plugins.py

index 7081797..26eefaf 100644 (file)
@@ -39,6 +39,43 @@ C = Conf()
 
 class PluginManager(object):
 
+    _subSystems = {
+        'admin': '/{admin}',
+        'auth': '/auth',
+        'availability': '/availability',
+        'backup': '/backup/util/ui',
+        'badges': '/badges',
+        'block': '/blocks',
+        'blog': '/blog',
+        'cache': '/cache',
+        'calendar': '/calendar',
+        'cohort': '/cohort',
+        'course': '/course',
+        'editor': '/lib/editor',
+        'enrol': '/enrol',
+        'files': '/files',
+        'form': '/lib/form',
+        'grades': '/grade',
+        'grading': '/grade/grading',
+        'group': '/group',
+        'message': '/message',
+        'mnet': '/mnet',
+        'my': '/my',
+        'notes': '/notes',
+        'plagiarism': '/plagiarism',
+        'portfolio': '/portfolio',
+        'publish': '/course/publish',
+        'question': '/question',
+        'rating': '/rating',
+        'register': '/{admin}/registration',
+        'repository': '/repository',
+        'rss': '/rss',
+        'role': '/{admin}/roles',
+        'tag': '/tag',
+        'user': '/user',
+        'webservice': '/webservice'
+    }
+
     _pluginTypesPath = {
         'mod': '/mod',
         'auth': '/auth',
@@ -132,6 +169,24 @@ class PluginManager(object):
         return (t, name)
 
     @classmethod
+    def getSubsystems(cls):
+        """Return the list of subsytems and their relative directory"""
+        return cls._subSystems
+
+    @classmethod
+    def getSubsystemDirectory(cls, subsystem, M=None):
+        """Return the subsystem directory, absolute if M is passed"""
+        path = cls._subSystems.get(subsystem)
+        if not path:
+            raise ValueError('Unknown subsystem')
+
+        if M:
+            path = path.replace('{admin}', M.get('admin', 'admin'))
+            path = os.path.join(M.get('path'), path.strip('/'))
+
+        return path
+
+    @classmethod
     def getSubtypes(cls, M):
         """Get the sub plugins declared in an instance"""
         regex = re.compile(r'\s*(?P<brackets>[\'"])(.*?)(?P=brackets)\s*=>\s*(?P=brackets)(.*?)(?P=brackets)')