Commit 4feda8e24f93b0dd5b2f50b533275921dfb5601f
1 parent
50b1814f
Exists in
master
and in
1 other branch
minor cleanup in main.py
Showing
1 changed file
with
9 additions
and
9 deletions
Show diff stats
perguntations/main.py
| 1 | #!/usr/bin/env python3 | 1 | #!/usr/bin/env python3 |
| 2 | 2 | ||
| 3 | ''' | 3 | ''' |
| 4 | -Main file that starts the application and the web server | 4 | +Start application and web server |
| 5 | ''' | 5 | ''' |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | # python standard library | 8 | # python standard library |
| 9 | import argparse | 9 | import argparse |
| 10 | import logging | 10 | import logging |
| 11 | +import logging.config | ||
| 11 | import os | 12 | import os |
| 12 | from os import environ, path | 13 | from os import environ, path |
| 13 | import ssl | 14 | import ssl |
| 14 | import sys | 15 | import sys |
| 15 | -# from typing import Any, Dict | ||
| 16 | 16 | ||
| 17 | # this project | 17 | # this project |
| 18 | from perguntations.app import App, AppException | 18 | from perguntations.app import App, AppException |
| @@ -20,7 +20,6 @@ from perguntations.serve import run_webserver | @@ -20,7 +20,6 @@ from perguntations.serve import run_webserver | ||
| 20 | from perguntations.tools import load_yaml | 20 | from perguntations.tools import load_yaml |
| 21 | from perguntations import APP_NAME, APP_VERSION | 21 | from perguntations import APP_NAME, APP_VERSION |
| 22 | 22 | ||
| 23 | - | ||
| 24 | # ---------------------------------------------------------------------------- | 23 | # ---------------------------------------------------------------------------- |
| 25 | def parse_cmdline_arguments(): | 24 | def parse_cmdline_arguments(): |
| 26 | ''' | 25 | ''' |
| @@ -32,7 +31,6 @@ def parse_cmdline_arguments(): | @@ -32,7 +31,6 @@ def parse_cmdline_arguments(): | ||
| 32 | 'included with this software before running the server.') | 31 | 'included with this software before running the server.') |
| 33 | parser.add_argument('testfile', | 32 | parser.add_argument('testfile', |
| 34 | type=str, | 33 | type=str, |
| 35 | - # nargs='+', # TODO | ||
| 36 | help='tests in YAML format') | 34 | help='tests in YAML format') |
| 37 | parser.add_argument('--allow-all', | 35 | parser.add_argument('--allow-all', |
| 38 | action='store_true', | 36 | action='store_true', |
| @@ -121,7 +119,9 @@ def main(): | @@ -121,7 +119,9 @@ def main(): | ||
| 121 | 119 | ||
| 122 | # --- Setup logging ------------------------------------------------------ | 120 | # --- Setup logging ------------------------------------------------------ |
| 123 | logging.config.dictConfig(get_logger_config(args.debug)) | 121 | logging.config.dictConfig(get_logger_config(args.debug)) |
| 124 | - logging.info('====================== Start Logging ======================') | 122 | + logger = logging.getLogger(__name__) |
| 123 | + | ||
| 124 | + logger.info('====================== Start Logging ======================') | ||
| 125 | 125 | ||
| 126 | # --- start application -------------------------------------------------- | 126 | # --- start application -------------------------------------------------- |
| 127 | config = { | 127 | config = { |
| @@ -137,8 +137,8 @@ def main(): | @@ -137,8 +137,8 @@ def main(): | ||
| 137 | try: | 137 | try: |
| 138 | app = App(config) | 138 | app = App(config) |
| 139 | except AppException: | 139 | except AppException: |
| 140 | - logging.critical('Failed to start application.') | ||
| 141 | - sys.exit(-1) | 140 | + logger.critical('Failed to start application.') |
| 141 | + sys.exit(1) | ||
| 142 | 142 | ||
| 143 | # --- get SSL certificates ----------------------------------------------- | 143 | # --- get SSL certificates ----------------------------------------------- |
| 144 | if 'XDG_DATA_HOME' in os.environ: | 144 | if 'XDG_DATA_HOME' in os.environ: |
| @@ -151,8 +151,8 @@ def main(): | @@ -151,8 +151,8 @@ def main(): | ||
| 151 | ssl_opt.load_cert_chain(path.join(certs_dir, 'cert.pem'), | 151 | ssl_opt.load_cert_chain(path.join(certs_dir, 'cert.pem'), |
| 152 | path.join(certs_dir, 'privkey.pem')) | 152 | path.join(certs_dir, 'privkey.pem')) |
| 153 | except FileNotFoundError: | 153 | except FileNotFoundError: |
| 154 | - logging.critical('SSL certificates missing in %s', certs_dir) | ||
| 155 | - sys.exit(-1) | 154 | + logger.critical('SSL certificates missing in %s', certs_dir) |
| 155 | + sys.exit(1) | ||
| 156 | 156 | ||
| 157 | # --- run webserver ---------------------------------------------------- | 157 | # --- run webserver ---------------------------------------------------- |
| 158 | run_webserver(app=app, ssl_opt=ssl_opt, port=args.port, debug=args.debug) | 158 | run_webserver(app=app, ssl_opt=ssl_opt, port=args.port, debug=args.debug) |