comparison launch @ 48:f89b560b7278 draft

Ensure correct exit status.
author David Barts <n5jrn@me.com>
date Thu, 30 May 2019 20:16:39 -0700
parents 879ec681f7e3
children
comparison
equal deleted inserted replaced
47:879ec681f7e3 48:f89b560b7278
26 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)") 26 opt("-p", "--port", default=8080, help="port to listen on (default: 8080)")
27 opt("-s", "--static", action="store_true", help="serve static files") 27 opt("-s", "--static", action="store_true", help="serve static files")
28 opt("directory", default=".", help="directory to serve", nargs='?') 28 opt("directory", default=".", help="directory to serve", nargs='?')
29 opt("path", default="/", help="URL path to serve", nargs='?') 29 opt("path", default="/", help="URL path to serve", nargs='?')
30 args = parser.parse_args(sys.argv[1:]) 30 args = parser.parse_args(sys.argv[1:])
31
31 mylog = logging.getLogger(MYNAME) 32 mylog = logging.getLogger(MYNAME)
32 mylog.addHandler(logging.StreamHandler()) 33 mylog.addHandler(logging.StreamHandler())
33 mylog.setLevel(logging.DEBUG if args.debug else logging.INFO) 34 mylog.setLevel(logging.DEBUG if args.debug else logging.INFO)
35
34 app, errors = launch(fsroot=args.directory, urlroot=args.path, logger=mylog, 36 app, errors = launch(fsroot=args.directory, urlroot=args.path, logger=mylog,
35 encoding=args.encoding, static=args.static) 37 encoding=args.encoding, static=args.static)
36 if errors: 38 if errors:
37 action = "continuing" if args.force else "aborting" 39 action = "continuing" if args.force else "aborting"
38 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format( 40 sys.stderr.write("{0}: {1} error{2} detected, {3}\n".format(
39 MYNAME, errors, "" if errors == 1 else "s", action)) 41 MYNAME, errors, "" if errors == 1 else "s", action))
40 if not args.force: sys.exit(1) 42 if not args.force: sys.exit(1)
41 43
42 if not args.compile: 44 if not args.compile:
43 app.run(host=args.bind, port=args.port) 45 app.run(host=args.bind, port=args.port)
46
47 sys.exit(1 if errors else 0)