-
Notifications
You must be signed in to change notification settings - Fork 1
/
settings.py
41 lines (40 loc) · 1.12 KB
/
settings.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
def entryToKVal(entry):
if not isinstance(entry, dict):
return entry, None
if not "vartype" in entry:
return None, None
if entry["vartype"] == "compound" or entry["vartype"] == "template":
d = dict()
iterval = entry["compounds"] if "compounds" in entry else entry["varvalue"]
for e in iterval:
k,v = entryToKVal(e)
if v == None:
continue
if v == {}:
continue
if k in d:
if not isinstance(d[k], list):
d[k] = [d[k], v]
else:
d[k].append(v)
else:
d[k]=v
return entry["varid"], d
else:
return entry["varid"], entry["varvalue"]
def listToDict(entries):
d = dict()
for ent in entries:
k,v = entryToKVal(ent)
if v == None:
continue
if v == {}:
continue
if k in d:
if not isinstance(d[k], list):
d[k] = [d[k], v]
else:
d[k].append(v)
else:
d[k]=v
return d