# HG changeset patch # User Paul Boddie # Date 1487864342 -3600 # Node ID 97ec110d65cf9df12f1d05a125f5067276bab26f # Parent d1d907801d42259dc2de1fd4dc3e6affe997a84e Added a "reset all" option removing the data directory. Added option synonyms. diff -r d1d907801d42 -r 97ec110d65cf docs/lplc.1 --- a/docs/lplc.1 Thu Feb 23 16:37:43 2017 +0100 +++ b/docs/lplc.1 Thu Feb 23 16:39:02 2017 +0100 @@ -24,31 +24,34 @@ The following options may be specified: .PP .TP -.B \-c -Only partially compile the program; do not attempt to build or link it +.BR \-c ", " \-\-compile +Only partially compile the program; do not build or link it .TP -.B \-E +.BR \-E ", " \-\-no\-env Ignore environment variables affecting the module search path .TP -.B \-g +.BR \-g ", " \-\-debug Generate debugging information for the built executable .TP -.B \-P +.BR \-P ", " \-\-show\-path Show the module search path .TP -.B \-q +.BR \-q ", " \-\-quiet Silence messages produced when building an executable .TP -.B \-r -Reset (discard) cached program information; inspect the whole program again +.BR \-r ", " \-\-reset +Reset (discard) cached information; inspect the whole program again .TP -.B \-t +.BR \-R ", " \-\-reset\-all +Reset (discard) all program details including translated code +.TP +.BR \-t ", " \-\-no\-timing Silence timing messages .TP -.B \-tb +.BR \-tb ", " \-\-traceback Provide a traceback for any internal errors (development only) .TP -.B \-v +.BR \-v ", " \-\-verbose Report compiler activities in a verbose fashion (development only) .PP Some options may be followed by values, either immediately after the option @@ -93,7 +96,7 @@ A collection of directories that are searched before those in the collection comprising the default "module search path". This collection, if already defined in the environment, may be excluded by specifying the -.B \-E +.BR \-E " (or " \-\-no\-env ) option. .SH AUTHOR Paul Boddie diff -r d1d907801d42 -r 97ec110d65cf lplc --- a/lplc Thu Feb 23 16:37:43 2017 +0100 +++ b/lplc Thu Feb 23 16:39:02 2017 +0100 @@ -22,8 +22,8 @@ VERSION = "0.1" from errors import * -from os import environ, rename -from os.path import abspath, exists, isfile, join, split +from os import environ, listdir, remove, rename +from os.path import abspath, exists, isdir, isfile, join, split from pyparser import error from subprocess import Popen, PIPE from time import time @@ -82,6 +82,17 @@ else: return l, needed +def remove_all(dirname): + + "Remove 'dirname' and its contents." + + for filename in listdir(dirname): + pathname = join(dirname, filename) + if isdir(pathname): + remove_all(pathname) + else: + remove(pathname) + # Main program. if __name__ == "__main__": @@ -98,21 +109,32 @@ Compile the program whose principal file is given in place of . The following options may be specified: --c Only partially compile the program; do not attempt to build or link it --E Ignore environment variables affecting the module search path --g Generate debugging information for the built executable --P Show the module search path --q Silence messages produced when building an executable --r Reset (discard) cached program information; inspect the whole program again --t Silence timing messages --tb Provide a traceback for any internal errors (development only) --v Report compiler activities in a verbose fashion (development only) +-c Only partially compile the program; do not build or link it +--compile Equivalent to -c +-E Ignore environment variables affecting the module search path +--no-env Equivalent to -E +-g Generate debugging information for the built executable +--debug Equivalent to -g +-P Show the module search path +--show-path Equivalent to -P +-q Silence messages produced when building an executable +--quiet Equivalent to -q +-r Reset (discard) cached information; inspect the whole program again +--reset Equivalent to -r +-R Reset (discard) all program details including translated code +--reset-all Equivalent to -R +-t Silence timing messages +--no-timing Equivalent to -t +-tb Provide a traceback for any internal errors (development only) +--traceback Equivalent to -tb +-v Report compiler activities in a verbose fashion (development only) +--verbose Equivalent to -v Some options may be followed by values, either immediately after the option (without any space between) or in the arguments that follow them: --o Indicate the output executable name --W Show warnings on the topics indicated +-o Indicate the output executable name +-W Show warnings on the topics indicated Currently, the following warnings are supported: @@ -152,6 +174,7 @@ make = True make_verbose = True reset = False + reset_all = False timings = True traceback = False verbose = False @@ -166,15 +189,16 @@ needed = None for arg in args: - if arg == "-c": make = False - elif arg == "-E": ignore_env = True - elif arg == "-g": debug = True - elif arg == "-q": make_verbose = False - elif arg == "-r": reset = True - elif arg == "-t": timings = False - elif arg == "-tb": traceback = True + if arg in ("-c", "--compile"): make = False + elif arg in ("-E", "--no-env"): ignore_env = True + elif arg in ("-g", "--debug"): debug = True + elif arg in ("-q", "--quiet"): make_verbose = False + elif arg in ("-r", "--reset"): reset = True + elif arg in ("-R", "--reset-all"): reset_all = True + elif arg in ("-t", "--no-timing"): timings = False + elif arg in ("-tb", "--traceback"): traceback = True elif arg.startswith("-o"): l, needed = start_arg_list(outputs, arg, "-o", 1) - elif arg == "-v": verbose = True + elif arg == ("-v", "--verbose"): verbose = True elif arg.startswith("-W"): l, needed = start_arg_list(warnings, arg, "-W", 1) else: l.append(arg) @@ -193,7 +217,7 @@ # Show the module search path if requested. - if "-P" in args: + if "-P" in args or "--show-path" in args: for libdir in libdirs: print libdir sys.exit(0) @@ -227,6 +251,11 @@ output_dir = join(datadir, "_output") generated_dir = join(datadir, "_generated") + # Perform any full reset of the working data. + + if reset_all: + remove_all(datadir) + # Load the program. try: