comparison foodtruck/main.py @ 587:d4a01a023998

admin: Add "FoodTruck" admin panel from the side experiment project.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 16 Jan 2016 14:24:35 -0800
parents
children b884bef3e611
comparison
equal deleted inserted replaced
586:59268b4d8c71 587:d4a01a023998
1 import sys
2 import logging
3 import argparse
4 from .web import app
5
6
7 logger = logging.getLogger(__name__)
8
9
10 def main():
11 parser = argparse.ArgumentParser(
12 description="FoodTruck command line utility")
13 parser.add_argument(
14 '--debug',
15 help="Show debug information",
16 action='store_true')
17 parser.add_argument(
18 '--version',
19 help="Print version and exit",
20 action='store_true')
21
22 args = parser.parse_args()
23 if args.version:
24 try:
25 from .__version__ import version
26 except ImportError:
27 print("Can't find version information.")
28 args.exit(1)
29 print("FoodTruck %s" % version)
30 args.exit(0)
31
32 root_logger = logging.getLogger()
33 root_logger.setLevel(logging.INFO)
34 if args.debug:
35 root_logger.setLevel(logging.DEBUG)
36
37 log_handler = logging.StreamHandler(sys.stdout)
38 if args.debug:
39 log_handler.setLevel(logging.DEBUG)
40 else:
41 log_handler.setLevel(logging.INFO)
42 root_logger.addHandler(log_handler)
43
44 try:
45 app.run(debug=args.debug, threaded=True)
46 except SystemExit:
47 # This is needed for Werkzeug's code reloader to be able to correctly
48 # shutdown the child process in order to restart it (otherwise, SSE
49 # generators will keep it alive).
50 from .views import baking
51 logger.debug("Shutting down SSE generators from main...")
52 baking.server_shutdown = True
53 raise
54