-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbirds_and_snakes.py
74 lines (55 loc) · 1.73 KB
/
birds_and_snakes.py
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import sys
import argparse
import logging
import logging.handlers
from logging.config import dictConfig
from bas.dev.client import DevClient
from bas.main import run_game
from bas.manager import Manager
logger = logging.getLogger(__name__)
def init_logger(debug):
dictConfig(DEFAULT_LOGGING)
formatter = logging.Formatter(
'%(asctime)s - %(levelname)-8s %(name)-12s: %(message)s')
logging.root.setLevel(logging.DEBUG)
if debug:
activate_stream_logging(formatter)
activate_file_logging(formatter)
def activate_stream_logging(formatter):
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.INFO)
console_handler.setFormatter(formatter)
logging.root.addHandler(console_handler)
def activate_file_logging(formatter):
file_handler = logging.FileHandler(
'history.log',
mode='w',
encoding='utf-8'
)
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(formatter)
logging.root.addHandler(file_handler)
def load_args():
parser = argparse.ArgumentParser(prog='birds_and_snakes.py',
epilog='Enjoy the game!')
parser.add_argument('-c', '--client', action='store_true',
help='Launch debug client')
parser.add_argument('-m', '--manager', metavar='COMMAND',
help='Manager interface')
return parser.parse_args()
def handle_args():
args = load_args()
if args.client:
run_client()
if args.manager:
Manager().command(args.manager)
sys.exit()
return
def run_client():
client = DevClient()
client.start()
client.join()
sys.exit()
if __name__ == '__main__':
handle_args()
run_game()