javaclass

runclass.py

118:714a1d918aa9
2005-01-13 Paul Boddie Commented out various trace statements for improved high-level testing. Added the runclass utility which supports running of Java classes through their public, static main methods.
     1 #!/usr/bin/env python     2      3 "Run class files."     4      5 import classhook     6      7 def load_class(class_name):     8      9     "Load the class with the given 'class_name'."    10     11     class_name_parts = class_name.split(".")    12     if len(class_name_parts) == 1:    13         module = __import__("__this__", globals(), locals(), [class_name])    14         obj = getattr(module, class_name)    15     else:    16         obj = __import__(class_name, globals(), locals())    17         for part in class_name_parts[1:]:    18             obj = getattr(obj, part)    19     20     return obj    21     22 def run_class(cls, args):    23     cls.main(args)    24     25 if __name__ == "__main__":    26     import sys    27     cls = load_class(sys.argv[1])    28     run_class(cls, sys.argv[2:])    29     30 # vim: tabstop=4 expandtab shiftwidth=4