comparison launch @ 47:879ec681f7e3 draft

Add --compile option.
author David Barts <n5jrn@me.com>
date Thu, 30 May 2019 20:14:14 -0700
parents 997d0c8c174f
children f89b560b7278
comparison
equal deleted inserted replaced
46:997d0c8c174f 47:879ec681f7e3
17 # M a i n P r o g r a m 17 # M a i n P r o g r a m
18 18
19 parser = ArgumentParser(prog=sys.argv[0], usage="%(prog)s [options] [directory [path]]") 19 parser = ArgumentParser(prog=sys.argv[0], usage="%(prog)s [options] [directory [path]]")
20 opt = parser.add_argument 20 opt = parser.add_argument
21 opt("-b", "--bind", default="localhost", help="address to bind to (default: localhost)") 21 opt("-b", "--bind", default="localhost", help="address to bind to (default: localhost)")
22 opt("-c", "--compile", action="store_true", help="compile .py files only; do not run a server")
22 opt("-d", "--debug", action="store_true", help="enable debug mode") 23 opt("-d", "--debug", action="store_true", help="enable debug mode")
23 opt("-e", "--encoding", default=ENCODING, help="encoding to use (default {0})".format(ENCODING)) 24 opt("-e", "--encoding", default=ENCODING, help="encoding to use (default {0})".format(ENCODING))
24 opt("-f", "--force", action="store_true", help="do not abort on errors") 25 opt("-f", "--force", action="store_true", help="do not abort on errors")
25 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)") 26 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)")
26 opt("-s", "--static", action="store_true", help="serve static files") 27 opt("-s", "--static", action="store_true", help="serve static files")
35 if errors: 36 if errors:
36 action = "continuing" if args.force else "aborting" 37 action = "continuing" if args.force else "aborting"
37 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format( 38 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format(
38 MYNAME, errors, "" if errors == 1 else "s", action)) 39 MYNAME, errors, "" if errors == 1 else "s", action))
39 if not args.force: sys.exit(1) 40 if not args.force: sys.exit(1)
40 app.run(host=args.bind, port=args.port) 41
42 if not args.compile:
43 app.run(host=args.bind, port=args.port)