From 23c9c26d270ff766133e7aeebffc99a35633ef41 Mon Sep 17 00:00:00 2001 From: Luke Macken Date: Tue, 15 Jan 2008 17:42:05 -0500 Subject: Simplify our modules by auto-detecting them and registering their handlers - Auto-detect and load all FuncModules. This obsoletes the need to have our modules define a register_rpc method. - Use introspection in our FuncModule to auto-register all method handlers that do not being with an underscore. This obsoletes the need to hardcode methods in our modules. - Remove all __init__ methods from our modules, along with register_rpc - Modify the func-create-module script to reflect these changes. Note that doing 'from modules import func_module' is no longer supported in our modules, do to some interesting path issues with our auto-detection code. Supported methods are now: 'import func_module' or 'from func.minion.modules import func_module' --- scripts/func-create-module | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'scripts') diff --git a/scripts/func-create-module b/scripts/func-create-module index afb4d09..7cbf9eb 100755 --- a/scripts/func-create-module +++ b/scripts/func-create-module @@ -10,9 +10,7 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. TEMPLATE = """\ -from modules import func_module -# Add your imports here -import sub_process +import func_module class %s(func_module.FuncModule): @@ -21,17 +19,7 @@ class %s(func_module.FuncModule): api_version = "0.0.1" description = "%s" - def __init__(self): - self.methods = { %s - } - func_module.FuncModule.__init__(self) - -%s - - -methods = %s() -register_rpc = methods.register_rpc """ @@ -40,12 +28,9 @@ def populate_template(module_name, desc, methods): Makes the method strings and populates the template. """ actual_methods = "" - method_str_dict = "" for method in methods: - method_str_dict += ' "%s": self.%s,\n' % (method, method) - actual_methods += " def self.%s(self):\n pass\n\n" % method - return TEMPLATE % (module_name, desc, - method_str_dict[:-1], actual_methods[:-2], module_name) + actual_methods += " def %s(self):\n pass\n\n" % method + return TEMPLATE % (module_name, desc, actual_methods[:-2]) if __name__ == '__main__': @@ -63,4 +48,4 @@ if __name__ == '__main__': file_obj = open(file_name, "w") file_obj.write(populate_template(module_name, desc, methods)) file_obj.close() - print "Your module is ready to be hacked on. Wrote out to %s." % file_name \ No newline at end of file + print "Your module is ready to be hacked on. Wrote out to %s." % file_name -- cgit