summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2008-01-15 17:42:05 -0500
committerLuke Macken <lmacken@redhat.com>2008-01-15 17:42:05 -0500
commit23c9c26d270ff766133e7aeebffc99a35633ef41 (patch)
treed68c5030efd41b5de10dcf7d92b1fa2c0c86b445 /scripts
parentc4371ce647118902dd7574394d86c690c9be686e (diff)
downloadthird_party-func-23c9c26d270ff766133e7aeebffc99a35633ef41.tar.gz
third_party-func-23c9c26d270ff766133e7aeebffc99a35633ef41.tar.xz
third_party-func-23c9c26d270ff766133e7aeebffc99a35633ef41.zip
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'
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/func-create-module23
1 files changed, 4 insertions, 19 deletions
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