Created
July 2, 2015 14:49
-
-
Save cmltaWt0/9e4fbfdb700a71f3e426 to your computer and use it in GitHub Desktop.
get_plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-def get_plugin(funcName, prefix='fsm.fsm_plugin.'): | |
+def get_plugin(funcName, prefix='.fsm_plugin.'): | |
""" | |
Import and call plugin func for this object. | |
""" | |
@@ -150,7 +151,18 @@ def get_plugin(funcName, prefix='fsm.fsm_plugin.'): | |
if not funcName: | |
raise ValueError('invalid call_plugin() with no funcName!') | |
i = funcName.rindex('.') | |
- modName = prefix + funcName[:i] | |
+ | |
+ app_name = None | |
+ pattern = '*/fsm_plugin/*.py' | |
+ plugins_paths = glob.glob(pattern) | |
+ for path in plugins_paths: | |
+ if funcName[:i] in path: | |
+ app_name = path.split('/')[0] | |
+ break | |
+ if not app_name: | |
+ raise ValueError('there is no such plugin %s in project!' % funcName[:i]) | |
+ | |
+ modName = app_name + prefix + funcName[:i] | |
funcName = funcName[i + 1:] | |
mod = importlib.import_module(modName) | |
return getattr(mod, funcName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment