-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_server.py
More file actions
executable file
·56 lines (45 loc) · 1.87 KB
/
Copy pathrun_server.py
File metadata and controls
executable file
·56 lines (45 loc) · 1.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
import logging
import argparse
from server import app, socketio
log = logging.getLogger(__name__)
__version__ = (0, 0, 1)
def main():
# argparse setup
# noinspection PyTypeChecker
parser = argparse.ArgumentParser(
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description='datenight server')
# optional arguments
parser.add_argument('-v', action='count', default=0,
help="verbosity increases with each 'v' | "
"critical/error/warning/info/debug")
parser.add_argument('-a', '--all-interfaces', action="store_true",
help="Listen on 0.0.0.0? (otherwise 127.0.0.1)")
parser.add_argument('-p', '--port', default=5500, type=int,
help="port to listen on")
parser.add_argument('-d', '--debug', action="store_true",
help="run in debug mode "
"(Warning: don't run this with -a)")
parser.add_argument('-V', '--version', action='version',
version="%(prog)s v{}".format(
'.'.join(map(str, __version__))),
help="Show version and exit")
args = parser.parse_args()
# logger setup
level = max(10, 50 - (10 * args.v))
print(f'Logging level is: {logging.getLevelName(level)}')
logger = logging.getLogger(__name__)
logger.setLevel(level)
formatter = logging.Formatter('%(asctime)s: %(levelname)s:\t%(message)s')
sh = logging.StreamHandler()
sh.setFormatter(formatter)
logger.addHandler(sh)
logger = logging.getLogger('server')
logger.setLevel(level)
logger.addHandler(sh)
# run flask
host = "0.0.0.0" if args.all_interfaces else "127.0.0.1"
socketio.run(app, host=host, port=args.port, debug=args.debug)
if __name__ == '__main__':
main()