changeset 3:65d9a7c7ac63

other misc improvements
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 10 May 2011 10:26:19 -0700
parents 6cb7696edc4d
children 5ce55f6c8964
files pyloader/invoke.py pyloader/loader.py
diffstat 2 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/pyloader/invoke.py	Tue May 10 09:28:40 2011 -0700
+++ b/pyloader/invoke.py	Tue May 10 10:26:19 2011 -0700
@@ -7,5 +7,17 @@
         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)
--- a/pyloader/loader.py	Tue May 10 09:28:40 2011 -0700
+++ b/pyloader/loader.py	Tue May 10 10:26:19 2011 -0700
@@ -8,6 +8,8 @@
 import os
 import sys
 
+__all__ = ['import_dotted_path', 'load']
+
 def import_dotted_path(module):
   path = module.split('.')
   module = __import__(module)