summaryrefslogtreecommitdiffstats
path: root/func
diff options
context:
space:
mode:
authorLouis Coilliot <louis.coilliot@wazemmes.org>2008-11-04 12:47:27 -0500
committerAdrian Likins <alikins@redhat.com>2008-11-04 12:47:27 -0500
commit4531fe7dcef7b6ecf1bce0670a83bb22214bf495 (patch)
treee9ebdee26f733f9c9a6fba9928a91165b8d90558 /func
parentdaebde27b3a5bb9e19b83b64c5a65e3515432ffa (diff)
add func_getargs.py module from Louis Coilliot
Adds some introspection support using the "inspect" module
Diffstat (limited to 'func')
-rw-r--r--func/minion/modules/func_getargs.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/func/minion/modules/func_getargs.py b/func/minion/modules/func_getargs.py
new file mode 100644
index 0000000..e9270ff
--- /dev/null
+++ b/func/minion/modules/func_getargs.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+#
+# Copyright 2008
+# Louis Coilliot <louis.coilliot@wazemmes.org>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+from platform import python_version_tuple as pv
+import sys
+import inspect
+import func_module
+
+class getArgs(func_module.FuncModule):
+ version = "0.0.1"
+ api_version = "0.0.1"
+ description = "Get args of methods of the class in a func module"
+
+ def get(self, modname, methodname):
+ """Returns a list of args for the specified method in the class of a func module.
+ This is useful when register_method_args is not defined (or not properly)
+ """
+ vtuple=pv()
+ pyver=vtuple[0]+'.'+vtuple[1]
+ sys.path.append('/usr/lib/python'+pyver+'/site-packages/func/minion/modules/')
+ the_mod=__import__(modname)
+
+ name,data=inspect.getmembers(the_mod, inspect.isclass)[0]
+ the_class=modname+'.'+name
+
+ c=getattr(the_mod, name)
+
+ return [ arg for arg in inspect.getargspec(eval('c.'+methodname))[0] if arg != 'self' ]
+
+
+ def register_method_args(self):
+ """Implementing the method arg getter"""
+ return {
+ 'get':{
+ 'args':{
+ 'modname':{
+ 'type':'string',
+ 'optional':False,
+ 'description':'The module name you want to check'
+ },
+ 'methodname':{
+ 'type':'string',
+ 'optional':False,
+ 'description':'The method name you want to check'
+ }
+ },
+ 'description':'Returns a list with the args of the method you checked'
+ }
+ }
+