Mercurial > cgi-bin > hgweb.cgi > tincan
comparison launch @ 4:0d47859f792a draft
Finally got "hello, world" working. Still likely many bugs.
author | David Barts <n5jrn@me.com> |
---|---|
date | Mon, 13 May 2019 12:38:26 -0700 |
parents | |
children | e88ab99914cf |
comparison
equal
deleted
inserted
replaced
3:c6902cded64d | 4:0d47859f792a |
---|---|
1 #!/usr/bin/env python3 | |
2 # XXX - This code must not be in tincan.py, because the built-in class | |
3 # loader will then confuse __main__.Page and tincan.Page, and fail to | |
4 # locate the code-behind. | |
5 | |
6 # I m p o r t s | |
7 | |
8 import os, sys | |
9 from argparse import ArgumentParser | |
10 from tincan import launch | |
11 | |
12 # V a r i a b l e s | |
13 | |
14 MYNAME = os.path.basename(sys.argv[0]) | |
15 | |
16 # M a i n P r o g r a m | |
17 | |
18 parser = ArgumentParser(prog=sys.argv[0], usage="%(prog)s [options] [directory [path]]") | |
19 opt = parser.add_argument | |
20 opt("-b", "--bind", default="localhost", help="address to bind to") | |
21 opt("-p", "--port", default=8080, help="port to listen on") | |
22 opt("directory", default=".", help="directory to serve", nargs='?') | |
23 opt("path", default="/", help="URL path to serve", nargs='?') | |
24 args = parser.parse_args(sys.argv[1:]) | |
25 app, errors = launch(fsroot=args.directory, urlroot=args.path) | |
26 if errors: | |
27 sys.stderr.write("{0}: {1} error{2} detected, aborting\n".format( | |
28 sys.argv[0], errors, "" if errors == 1 else "s")) | |
29 sys.exit(1) | |
30 app.run(host=args.bind, port=args.port) |