Module to get arg list from func methods in the classes of the modules

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

the module is in attachment, FYI.

I wrote this primarily for Symbolic. Symbolic needs to get the arg list to create forms for WebUI operations based on func modules, and the register_method_args method is not always defined (that's a pity).

Perhaps it would be better to implement this in the inners of func, but as a func module it was quick to do.

Examples of use:
import func.overlord.client as fc
c = fc.Client("*")

print c.func_getargs.get('mount','umount')
print c.func_getargs.get('command','run')
print c.func_getargs.get('reboot','reboot')

will return (here on the minion 'kermit'):

{'kermit': ['dir', 'killall', 'force', 'lazy']}
{'kermit': ['command', 'env']}
{'kermit': ['when', 'message']}



Louis
#!/usr/bin/env python

#
# Copyright 2008
# Louis Coilliot <louis.coilliot@xxxxxxxxxxxx>
#
# 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'
                    }
                }

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list

[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux