-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
executable file
·56 lines (42 loc) · 1.59 KB
/
utils.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
def read_config(filename: str) -> dict:
teams = {}
with open(filename, "r") as f:
for line in f.readlines():
line = line.strip()
if line.startswith("TEAM "):
args = line[5:].split(":")
team_name = args[0]
if team_name in teams:
teams[team_name].update({
"color": args[1],
"details": args[2]
})
else:
teams[team_name] = {
"color": args[1],
"details": args[2],
"cars": []
}
elif line.startswith("CAR "):
args = line[4:].split(":")
if len(args) < 2: continue # TODO print error instead
team_name = args[0]
h5_file_name = args[1]
model_dict = {"model_file": h5_file_name}
if len(args) > 2:
model_name = args[2]
model_dict["name"] = model_name
if team_name not in teams:
teams[team_name] = {"cars": [model_dict]}
else:
teams[team_name]["cars"].append(model_dict)
else:
# TODO Add other config stuff if necessary
continue
return {"TEAMS": teams}
import json
def dump_utf8(data, **kwargs):
return json.dumps(data, **kwargs, ensure_ascii=False)
if __name__ == "__main__":
from pprint import pprint
pprint(read_config(".conf.example"))