diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/launch	Mon May 13 12:38:26 2019 -0700
@@ -0,0 +1,30 @@
+#!/usr/bin/env python3
+# XXX - This code must not be in tincan.py, because the built-in class
+# loader will then confuse __main__.Page and tincan.Page, and fail to
+# locate the code-behind.
+
+# I m p o r t s
+
+import os, sys
+from argparse import ArgumentParser
+from tincan import launch
+
+# V a r i a b l e s
+
+MYNAME = os.path.basename(sys.argv[0])
+
+# M a i n   P r o g r a m
+
+parser = ArgumentParser(prog=sys.argv[0], usage="%(prog)s [options] [directory [path]]")
+opt = parser.add_argument
+opt("-b", "--bind", default="localhost", help="address to bind to")
+opt("-p", "--port", default=8080, help="port to listen on")
+opt("directory", default=".", help="directory to serve", nargs='?')
+opt("path", default="/", help="URL path to serve", nargs='?')
+args = parser.parse_args(sys.argv[1:])
+app, errors = launch(fsroot=args.directory, urlroot=args.path)
+if errors:
+    sys.stderr.write("{0}: {1} error{2} detected, aborting\n".format(
+        sys.argv[0], errors, "" if errors == 1 else "s"))
+    sys.exit(1)
+app.run(host=args.bind, port=args.port)