Mercurial > hg > pyloader
view pyloader/invoke.py @ 3:65d9a7c7ac63
other misc improvements
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Tue, 10 May 2011 10:26:19 -0700 |
parents | 6cb7696edc4d |
children | 5ce55f6c8964 |
line wrap: on
line source
import inspect def call(obj, *args, **kwargs): """call a thing with string arguments""" inspected = obj if inspect.isclass(obj): inspected = obj.__init__ # inspect the ctor argspec = inspect.getargspec(inspected) if __name__ == '__main__': import sys from loader import load from optparse import OptionParser usage = '%prog Object arg1=value1 arg2=value2 [...]' description = 'invoke an Object given string arguments' parser = OptionParser(usage=usage, description=description) args = sys.argv[1:] if not args: parser.print_usage() parser.exit() obj_args = dict([i.split('=', 1) for i in args[1:]]) obj = load(args[0]) print call(obj, **obj_args)