From 1d16f0dd881b2ce08e528204dbb4de3f16bc56d6 Mon Sep 17 00:00:00 2001 From: Frederic Massart Date: Fri, 9 May 2014 15:46:00 +0800 Subject: [PATCH] Adding support for subsystems in PluginManager 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 | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/lib/plugins.py b/lib/plugins.py index 7081797..26eefaf 100644 --- a/lib/plugins.py +++ b/lib/plugins.py @@ -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[\'"])(.*?)(?P=brackets)\s*=>\s*(?P=brackets)(.*?)(?P=brackets)') -- 2.11.0