forked from Blarc/igralni-streznik
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
69 lines (59 loc) · 2.03 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
# -*- coding: utf-8 -*-
import getopt
import sys
from sledilnik.TrackerSetup import TrackerSetup
from src.restapi.GameApi import GameApi
def main(argv):
tracker_config_path = './tracker_config.yaml'
game_name = None
setup = False
create_test_game = False
try:
opts, args = getopt.getopt(
argv,
"ht:g:sn:d",
[
"help",
"tracker-config=",
"setup",
"game=",
"test"
]
)
except getopt.GetoptError:
help_text()
sys.exit(1)
for opt, arg in opts:
if opt in ("-h", "--help"):
help_text()
sys.exit()
elif opt in ("-t", "--tracker-config"):
print(f'Tracker config path: {arg}')
tracker_config_path = arg
elif opt in ("-s", "--setup"):
print('Running tracker setup')
setup = True
elif opt in ("-n", "--game"):
print(f'Game name: {arg}')
game_name = arg
elif opt in ("-d", "--test"):
print('Creating a game with id "test"')
create_test_game = True
if game_name is None:
raise Exception("Game name not specified.")
if setup:
TrackerSetup(tracker_config_path, f'./src/games/{game_name.lower()}/game_config.yaml').start()
else:
game_api = GameApi(game_name)
if create_test_game:
game_api.start_test_game_server()
game_api.start()
def help_text():
print("Usage:")
print("\t--help (-h) shows this help")
print("\t--tracker-config (-t) <path to tracker config> sets path to tracker config")
print("\t--setup (-s) runs tracker setup")
print("\t--game (-n) <game name> runs game server for given game")
print("\t--test (-d) creates a test game with longer game time")
if __name__ == '__main__':
main(sys.argv[1:])