1 #!/usr/bin/env python 2 3 from errors import * 4 from os.path import abspath, exists, join, split 5 from time import time 6 import importer 7 import sys 8 9 libdirs = [ 10 join(split(__file__)[0], "lib"), 11 "/usr/share/lichen/lib" 12 ] 13 14 def load_module(filename, module_name): 15 for libdir in libdirs: 16 path = join(libdir, filename) 17 if exists(path): 18 return i.load_from_file(path, module_name) 19 return None 20 21 def stopwatch(activity, now): 22 print >>sys.stderr, "%s took %.2f seconds" % (activity, time() - now) 23 return time() 24 25 # Main program. 26 27 if __name__ == "__main__": 28 args = sys.argv[2:] 29 path = libdirs + sys.path[:] 30 31 filename = abspath(sys.argv[1]) 32 path.append(split(filename)[0]) 33 34 verbose = "-v" in args 35 reset = "-r" in args 36 37 # Load the program. 38 39 try: 40 start = now = time() 41 42 i = importer.Importer(path, "_cache", verbose) 43 m = i.initialise(filename, reset) 44 i.finalise() 45 46 now = stopwatch("Inspection", now) 47 48 # Report any errors. 49 50 except ProcessingError, exc: 51 print exc 52 if "-tb" in args: 53 raise 54 elif "-exit" in args: 55 sys.exit(1) 56 57 except KeyboardInterrupt: 58 if "-exit" in args: 59 sys.exit(2) 60 else: 61 raise 62 63 else: 64 if "-exit" in args: 65 sys.exit(0) 66 67 # vim: tabstop=4 expandtab shiftwidth=4