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