comparison launch @ 39:ee19984ba31d draft

Merge in the header-includes branch to the trunk.
author David Barts <n5jrn@me.com>
date Tue, 28 May 2019 20:20:19 -0700
parents ce67eac10fc7
children df27cf08c093
comparison
equal deleted inserted replaced
23:e8b6ee7e5b6b 39:ee19984ba31d
5 5
6 # I m p o r t s 6 # I m p o r t s
7 7
8 import os, sys 8 import os, sys
9 from argparse import ArgumentParser 9 from argparse import ArgumentParser
10 from tincan import launch 10 from tincan import launch, ENCODING
11 11
12 # V a r i a b l e s 12 # V a r i a b l e s
13 13
14 MYNAME = os.path.basename(sys.argv[0]) 14 MYNAME = os.path.basename(sys.argv[0])
15 15
16 # M a i n P r o g r a m 16 # M a i n P r o g r a m
17 17
18 parser = ArgumentParser(prog=sys.argv[0], usage="%(prog)s [options] [directory [path]]") 18 parser = ArgumentParser(prog=sys.argv[0], usage="%(prog)s [options] [directory [path]]")
19 opt = parser.add_argument 19 opt = parser.add_argument
20 opt("-b", "--bind", default="localhost", help="address to bind to") 20 opt("-b", "--bind", default="localhost", help="address to bind to (default: localhost)")
21 opt("-p", "--port", default=8080, help="port to listen on") 21 opt("-d", "--debug", action="store_true", help="enable debug mode")
22 opt("-e", "--encoding", default=ENCODING, help="encoding to use (default {0})".format(ENCODING))
23 opt("-f", "--force", action="store_true", help="do not abort on errors")
24 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)")
22 opt("directory", default=".", help="directory to serve", nargs='?') 25 opt("directory", default=".", help="directory to serve", nargs='?')
23 opt("path", default="/", help="URL path to serve", nargs='?') 26 opt("path", default="/", help="URL path to serve", nargs='?')
24 args = parser.parse_args(sys.argv[1:]) 27 args = parser.parse_args(sys.argv[1:])
25 app, errors = launch(fsroot=args.directory, urlroot=args.path) 28 app, errors = launch(fsroot=args.directory, urlroot=args.path, debug=args.debug,
29 encoding=args.encoding)
26 if errors: 30 if errors:
27 sys.stderr.write("{0}: {1} error{2} detected, aborting\n".format( 31 action = "continuing" if args.force else "aborting"
28 MYNAME, errors, "" if errors == 1 else "s")) 32 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format(
29 sys.exit(1) 33 MYNAME, errors, "" if errors == 1 else "s", action))
34 if not args.force: sys.exit(1)
30 app.run(host=args.bind, port=args.port) 35 app.run(host=args.bind, port=args.port)