From 03eb195d13727093aea5f726e08065ab925d32d8 Mon Sep 17 00:00:00 2001 From: Thomas S Hatch Date: Fri, 22 Apr 2011 22:56:59 -0600 Subject: [PATCH] Add convenience call function to loader --- salt/loader.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/salt/loader.py b/salt/loader.py index e62a76adae..3616b991b6 100644 --- a/salt/loader.py +++ b/salt/loader.py @@ -34,6 +34,16 @@ def returners(opts): load = Loader(module_dirs, opts) return load.filter_func('returner') +def call(fun, arg=[], dirs=[]): + ''' + Directly call a function inside a loader directory + ''' + module_dirs = [ + os.path.join(distutils.sysconfig.get_python_lib(), 'salt/modules'), + ] + dirs + load = Loader(module_dirs) + return load.call(fun, args) + class Loader(object): ''' @@ -66,18 +76,17 @@ class Loader(object): docs[fun] = funcs[fun].__doc__ return docs - def call(self, fun, arg=[], dirs=[]): + def call(self, fun, arg=[]): ''' Call a function in the load path. ''' - dirs += self.module_dirs name = fun[:fun.rindex('.')] try: - fn_, path, desc = imp.find_module(name, dirs) + fn_, path, desc = imp.find_module(name, module_dirs) mod = imp.load_module(name, fn_, path, desc) except ImportError: # The module was not found, try to find a cython module - for mod_dir in dirs: + for mod_dir in module_dirs: for fn_ in os.listdir(mod_dir): if name == fn_[:fn_.rindex('.')]: # Found it, load the mod and break the loop