Mercurial > cgi-bin > hgweb.cgi > tincan
comparison launch @ 46:997d0c8c174f draft
Default for the launch callable should be not to log.
author | David Barts <n5jrn@me.com> |
---|---|
date | Thu, 30 May 2019 16:36:43 -0700 |
parents | df27cf08c093 |
children | 879ec681f7e3 |
comparison
equal
deleted
inserted
replaced
45:969f515b505b | 46:997d0c8c174f |
---|---|
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 import logging | |
10 from tincan import launch, ENCODING | 11 from tincan import launch, ENCODING |
11 | 12 |
12 # V a r i a b l e s | 13 # V a r i a b l e s |
13 | 14 |
14 MYNAME = os.path.basename(sys.argv[0]) | 15 MYNAME = os.path.basename(sys.argv[0]) |
24 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)") | 25 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)") |
25 opt("-s", "--static", action="store_true", help="serve static files") | 26 opt("-s", "--static", action="store_true", help="serve static files") |
26 opt("directory", default=".", help="directory to serve", nargs='?') | 27 opt("directory", default=".", help="directory to serve", nargs='?') |
27 opt("path", default="/", help="URL path to serve", nargs='?') | 28 opt("path", default="/", help="URL path to serve", nargs='?') |
28 args = parser.parse_args(sys.argv[1:]) | 29 args = parser.parse_args(sys.argv[1:]) |
29 app, errors = launch(fsroot=args.directory, urlroot=args.path, debug=args.debug, | 30 mylog = logging.getLogger(MYNAME) |
31 mylog.addHandler(logging.StreamHandler()) | |
32 mylog.setLevel(logging.DEBUG if args.debug else logging.INFO) | |
33 app, errors = launch(fsroot=args.directory, urlroot=args.path, logger=mylog, | |
30 encoding=args.encoding, static=args.static) | 34 encoding=args.encoding, static=args.static) |
31 if errors: | 35 if errors: |
32 action = "continuing" if args.force else "aborting" | 36 action = "continuing" if args.force else "aborting" |
33 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format( | 37 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format( |
34 MYNAME, errors, "" if errors == 1 else "s", action)) | 38 MYNAME, errors, "" if errors == 1 else "s", action)) |