-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (55 loc) · 2.33 KB
/
main.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
import argparse
import os
import logging
import datetime
import time
from uno.uno import UNO
from uno.manager import Manager
from uno import NAME_TO_CONTROLLER, NAME_TO_DISPLAYER
def print_example_usage():
print("Example usage:")
print("python", os.path.basename(__file__), '-c', 'TerminalController', '-d', 'TkDisplayer', 'TerminalDisplayer')
# testing
from queue import Queue
from uno.controller import TerminalController
from uno.manager import Manager
from uno.requests import PlayCard, GetUserInput, Reset
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='main',
description='UNO project for 18-500')
parser.add_argument('-l', '--log',
help='enable logging',
action='store_true',
default=False)
parser.add_argument('-c', '--controller_name',
help='the class name of the controller to use',
type=str,
default='TerminalController')
parser.add_argument('-d', '--displayer_names',
help='the class name of the displayer(s) to use',
type=str,
nargs='+',
default=['TerminalDisplayer'])
parser.add_argument('-u', '--url',
help='the url of the running website',
type=str,
default='http://172.26.72.28:5000')
args = parser.parse_args()
# get the classes the user wants to use
controller_class = NAME_TO_CONTROLLER[args.controller_name]
displayer_classes = [NAME_TO_DISPLAYER[displayer_name] for displayer_name in args.displayer_names]
# set up logging
logger: logging.Logger = logging.Logger(__file__)
date_time = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S')
path = os.path.join(os.path.dirname(__file__), f'uno/logs/log_{date_time}.log')
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
if args.log:
file_handler = logging.FileHandler(path)
logger.addHandler(file_handler)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(formatter)
else:
logger.addHandler(logging.NullHandler())
# create the objects from the classes
manager = Manager(controller_class, displayer_classes, logger, args.url)
manager.start()