javaclass

Changeset

118:714a1d918aa9
2005-01-13 Paul Boddie raw files shortlog changelog graph 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.
bytecode.py (file) classhook.py (file) runclass.py (file)
     1.1 --- a/bytecode.py	Tue Jan 11 00:59:20 2005 +0100
     1.2 +++ b/bytecode.py	Thu Jan 13 18:33:35 2005 +0100
     1.3 @@ -2257,10 +2257,10 @@
     1.4          elif super_class_module_name == this_class_module_name:
     1.5              obj = global_names[super_class_name]
     1.6          else:
     1.7 -            print "Importing", super_class_module_name, super_class_name
     1.8 +            #print "Importing", super_class_module_name, super_class_name
     1.9              obj = __import__(super_class_module_name, global_names, {}, [])
    1.10              for super_class_name_part in super_class_name_parts[1:] or [super_class_name]:
    1.11 -                print "*", obj, super_class_name_part
    1.12 +                #print "*", obj, super_class_name_part
    1.13                  obj = getattr(obj, super_class_name_part)
    1.14          return (obj,)
    1.15  
     2.1 --- a/classhook.py	Tue Jan 11 00:59:20 2005 +0100
     2.2 +++ b/classhook.py	Thu Jan 13 18:33:35 2005 +0100
     2.3 @@ -317,7 +317,7 @@
     2.4              class_file_init = {}
     2.5  
     2.6              for class_name in class_file_index:
     2.7 -                print "* Class", class_name
     2.8 +                #print "* Class", class_name
     2.9                  class_file = class_files[class_name]
    2.10                  translator = bytecode.ClassTranslator(class_file)
    2.11                  cls, external_names = translator.process(global_names)
    2.12 @@ -329,7 +329,7 @@
    2.13                  this_class_module, this_class_name = this_class_name_parts[:-1], this_class_name_parts[-1]
    2.14  
    2.15                  for external_name in external_names:
    2.16 -                    print "* Name", external_name
    2.17 +                    #print "* Name", external_name
    2.18                      external_name_parts = external_name.split(".")
    2.19                      external_class_module, external_class_name = external_name_parts[:-1], external_name_parts[-1]
    2.20  
    2.21 @@ -338,7 +338,7 @@
    2.22                      if len(external_name_parts) > 1 and this_class_module != external_class_module:
    2.23  
    2.24                          external_module_name = ".".join(external_class_module)
    2.25 -                        print "* Importing", external_module_name
    2.26 +                        #print "* Importing", external_module_name
    2.27                          obj = __import__(external_module_name, global_names, {}, [])
    2.28                          global_names[external_name_parts[0]] = obj
    2.29  
    2.30 @@ -351,7 +351,7 @@
    2.31                              # Either insert this name before the current class's
    2.32                              # name.
    2.33  
    2.34 -                            print "* Inserting", external_class_name
    2.35 +                            #print "* Inserting", external_class_name
    2.36                              class_file_init_index.insert(this_class_name_index, external_class_name)
    2.37  
    2.38                          except ValueError:
    2.39 @@ -359,7 +359,7 @@
    2.40                              # Or add this name in anticipation of the current
    2.41                              # class's name appearing.
    2.42  
    2.43 -                            print "* Including", external_class_name
    2.44 +                            #print "* Including", external_class_name
    2.45                              class_file_init_index.append(external_class_name)
    2.46  
    2.47                  # Add this class name to the initialisation index.
    2.48 @@ -370,10 +370,10 @@
    2.49  
    2.50              # Finally, call __clinit__ methods for all relevant classes.
    2.51  
    2.52 -            print "** Initialisation order", class_file_init_index
    2.53 +            #print "** Initialisation order", class_file_init_index
    2.54              for class_name in class_file_init_index:
    2.55                  cls, class_file = class_file_init[class_name]
    2.56 -                print "**", cls, class_file
    2.57 +                #print "**", cls, class_file
    2.58                  if hasattr(cls, "__clinit__"):
    2.59                      eval(cls.__clinit__.func_code, global_names)
    2.60  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/runclass.py	Thu Jan 13 18:33:35 2005 +0100
     3.3 @@ -0,0 +1,30 @@
     3.4 +#!/usr/bin/env python
     3.5 +
     3.6 +"Run class files."
     3.7 +
     3.8 +import classhook
     3.9 +
    3.10 +def load_class(class_name):
    3.11 +
    3.12 +    "Load the class with the given 'class_name'."
    3.13 +
    3.14 +    class_name_parts = class_name.split(".")
    3.15 +    if len(class_name_parts) == 1:
    3.16 +        module = __import__("__this__", globals(), locals(), [class_name])
    3.17 +        obj = getattr(module, class_name)
    3.18 +    else:
    3.19 +        obj = __import__(class_name, globals(), locals())
    3.20 +        for part in class_name_parts[1:]:
    3.21 +            obj = getattr(obj, part)
    3.22 +
    3.23 +    return obj
    3.24 +
    3.25 +def run_class(cls, args):
    3.26 +    cls.main(args)
    3.27 +
    3.28 +if __name__ == "__main__":
    3.29 +    import sys
    3.30 +    cls = load_class(sys.argv[1])
    3.31 +    run_class(cls, sys.argv[2:])
    3.32 +
    3.33 +# vim: tabstop=4 expandtab shiftwidth=4