1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lplc Tue Aug 30 16:51:10 2016 +0200
1.3 @@ -0,0 +1,67 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from errors import *
1.7 +from os.path import abspath, exists, join, split
1.8 +from time import time
1.9 +import importer
1.10 +import sys
1.11 +
1.12 +libdirs = [
1.13 + join(split(__file__)[0], "lib"),
1.14 + "/usr/share/lichen/lib"
1.15 + ]
1.16 +
1.17 +def load_module(filename, module_name):
1.18 + for libdir in libdirs:
1.19 + path = join(libdir, filename)
1.20 + if exists(path):
1.21 + return i.load_from_file(path, module_name)
1.22 + return None
1.23 +
1.24 +def stopwatch(activity, now):
1.25 + print >>sys.stderr, "%s took %.2f seconds" % (activity, time() - now)
1.26 + return time()
1.27 +
1.28 +# Main program.
1.29 +
1.30 +if __name__ == "__main__":
1.31 + args = sys.argv[2:]
1.32 + path = libdirs + sys.path[:]
1.33 +
1.34 + filename = abspath(sys.argv[1])
1.35 + path.append(split(filename)[0])
1.36 +
1.37 + verbose = "-v" in args
1.38 + reset = "-r" in args
1.39 +
1.40 + # Load the program.
1.41 +
1.42 + try:
1.43 + start = now = time()
1.44 +
1.45 + i = importer.Importer(path, "_cache", verbose)
1.46 + m = i.initialise(filename, reset)
1.47 + i.finalise()
1.48 +
1.49 + now = stopwatch("Inspection", now)
1.50 +
1.51 + # Report any errors.
1.52 +
1.53 + except ProcessingError, exc:
1.54 + print exc
1.55 + if "-tb" in args:
1.56 + raise
1.57 + elif "-exit" in args:
1.58 + sys.exit(1)
1.59 +
1.60 + except KeyboardInterrupt:
1.61 + if "-exit" in args:
1.62 + sys.exit(2)
1.63 + else:
1.64 + raise
1.65 +
1.66 + else:
1.67 + if "-exit" in args:
1.68 + sys.exit(0)
1.69 +
1.70 +# vim: tabstop=4 expandtab shiftwidth=4