diff options
author | Krzysztof A. Adamski <krzysztofa@gmail.com> | 2008-08-07 19:05:14 -0400 |
---|---|---|
committer | Krzysztof A. Adamski <krzysztofa@gmail.com> | 2008-08-07 19:05:14 -0400 |
commit | 9c7f1053c9823e9c39df3233f56a04368002ef9d (patch) | |
tree | 05dcb94375b64420aa994249b5fea6050e885000 | |
parent | b2ea14876b07a9a2a64adbb0ddd824e15c674ffe (diff) | |
download | func-9c7f1053c9823e9c39df3233f56a04368002ef9d.tar.gz func-9c7f1053c9823e9c39df3233f56a04368002ef9d.tar.xz func-9c7f1053c9823e9c39df3233f56a04368002ef9d.zip |
Pass reference to the parrent class to modules loaded by load_methods().
-rwxr-xr-x | func/module_loader.py | 9 | ||||
-rwxr-xr-x | func/overlord/client.py | 4 | ||||
-rw-r--r-- | func/overlord/overlord_module.py | 3 |
3 files changed, 8 insertions, 8 deletions
diff --git a/func/module_loader.py b/func/module_loader.py index a999de7..66045d1 100755 --- a/func/module_loader.py +++ b/func/module_loader.py @@ -39,17 +39,16 @@ def module_walker(topdir): return module_files -def load_methods(path, main_class): +def load_methods(path, main_class, parent_class=None): methods = {} - modules = load_modules(path, main_class) + modules = load_modules(path, main_class, parent_class=parent_class) for x in modules.keys(): for method in dir(modules[x]): if is_public_valid_method(modules[x], method): methods["%s.%s" % (x,method)]=getattr(modules[x], method) return methods -def load_modules(path='func/minion/modules/', main_class=func_module.FuncModule, blacklist=None): - +def load_modules(path='func/minion/modules/', main_class=func_module.FuncModule, blacklist=None, parent_class=None): python_path = distutils.sysconfig.get_python_lib() module_file_path = "%s/%s" % (python_path, path) (mod_path, mod_dir) = os.path.split(os.path.normpath(module_file_path)) @@ -96,7 +95,7 @@ def load_modules(path='func/minion/modules/', main_class=func_module.FuncModule, attr = getattr(blip, obj) if isclass(attr) and issubclass(attr, main_class): logger.debug("Loading %s module" % attr) - mods[mod_imp_name] = attr() + mods[mod_imp_name] = attr(parent_class) except ImportError, e: # A module that raises an ImportError is (for now) simply not loaded. diff --git a/func/overlord/client.py b/func/overlord/client.py index e68fdcc..54777e3 100755 --- a/func/overlord/client.py +++ b/func/overlord/client.py @@ -195,7 +195,7 @@ class Overlord(object): if init_ssl: self.setup_ssl() - self.methods = module_loader.load_methods('func/overlord/modules/', overlord_module.BaseModule) + self.methods = module_loader.load_methods('func/overlord/modules/', overlord_module.BaseModule, self) def setup_ssl(self, client_key=None, client_cert=None, ca=None): # defaults go: @@ -292,7 +292,7 @@ class Overlord(object): if module == "local": if method in self.methods.keys(): - return self.methods[method]() + return self.methods[method](*args) else: raise AttributeError("no such method") diff --git a/func/overlord/overlord_module.py b/func/overlord/overlord_module.py index 17a335d..9d01728 100644 --- a/func/overlord/overlord_module.py +++ b/func/overlord/overlord_module.py @@ -1,2 +1,3 @@ class BaseModule: - pass + def __init__(self, parent=None): + self.parent=parent |