# HG changeset patch # User Paul Boddie # Date 1105637615 -3600 # Node ID 714a1d918aa9a03bdc22bed60abba3051d371e5e # Parent c24f02c31ec98b1c0d4d4ab906ee3a89166dbfa0 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. diff -r c24f02c31ec9 -r 714a1d918aa9 bytecode.py --- a/bytecode.py Tue Jan 11 00:59:20 2005 +0100 +++ b/bytecode.py Thu Jan 13 18:33:35 2005 +0100 @@ -2257,10 +2257,10 @@ elif super_class_module_name == this_class_module_name: obj = global_names[super_class_name] else: - print "Importing", super_class_module_name, super_class_name + #print "Importing", super_class_module_name, super_class_name obj = __import__(super_class_module_name, global_names, {}, []) for super_class_name_part in super_class_name_parts[1:] or [super_class_name]: - print "*", obj, super_class_name_part + #print "*", obj, super_class_name_part obj = getattr(obj, super_class_name_part) return (obj,) diff -r c24f02c31ec9 -r 714a1d918aa9 classhook.py --- a/classhook.py Tue Jan 11 00:59:20 2005 +0100 +++ b/classhook.py Thu Jan 13 18:33:35 2005 +0100 @@ -317,7 +317,7 @@ class_file_init = {} for class_name in class_file_index: - print "* Class", class_name + #print "* Class", class_name class_file = class_files[class_name] translator = bytecode.ClassTranslator(class_file) cls, external_names = translator.process(global_names) @@ -329,7 +329,7 @@ this_class_module, this_class_name = this_class_name_parts[:-1], this_class_name_parts[-1] for external_name in external_names: - print "* Name", external_name + #print "* Name", external_name external_name_parts = external_name.split(".") external_class_module, external_class_name = external_name_parts[:-1], external_name_parts[-1] @@ -338,7 +338,7 @@ if len(external_name_parts) > 1 and this_class_module != external_class_module: external_module_name = ".".join(external_class_module) - print "* Importing", external_module_name + #print "* Importing", external_module_name obj = __import__(external_module_name, global_names, {}, []) global_names[external_name_parts[0]] = obj @@ -351,7 +351,7 @@ # Either insert this name before the current class's # name. - print "* Inserting", external_class_name + #print "* Inserting", external_class_name class_file_init_index.insert(this_class_name_index, external_class_name) except ValueError: @@ -359,7 +359,7 @@ # Or add this name in anticipation of the current # class's name appearing. - print "* Including", external_class_name + #print "* Including", external_class_name class_file_init_index.append(external_class_name) # Add this class name to the initialisation index. @@ -370,10 +370,10 @@ # Finally, call __clinit__ methods for all relevant classes. - print "** Initialisation order", class_file_init_index + #print "** Initialisation order", class_file_init_index for class_name in class_file_init_index: cls, class_file = class_file_init[class_name] - print "**", cls, class_file + #print "**", cls, class_file if hasattr(cls, "__clinit__"): eval(cls.__clinit__.func_code, global_names) diff -r c24f02c31ec9 -r 714a1d918aa9 runclass.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/runclass.py Thu Jan 13 18:33:35 2005 +0100 @@ -0,0 +1,30 @@ +#!/usr/bin/env python + +"Run class files." + +import classhook + +def load_class(class_name): + + "Load the class with the given 'class_name'." + + class_name_parts = class_name.split(".") + if len(class_name_parts) == 1: + module = __import__("__this__", globals(), locals(), [class_name]) + obj = getattr(module, class_name) + else: + obj = __import__(class_name, globals(), locals()) + for part in class_name_parts[1:]: + obj = getattr(obj, part) + + return obj + +def run_class(cls, args): + cls.main(args) + +if __name__ == "__main__": + import sys + cls = load_class(sys.argv[1]) + run_class(cls, sys.argv[2:]) + +# vim: tabstop=4 expandtab shiftwidth=4