-
Notifications
You must be signed in to change notification settings - Fork 11
/
genManifest.py
128 lines (111 loc) · 4.7 KB
/
genManifest.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/python3
from curses.ascii import isupper
from platform import release
import sys
from os import listdir
from os import mkdir
from os import remove
from os import path
import json
def convertJSON(infile,outfile):
with open(infile) as json_file:
data = json.load(json_file)
for build in data['builds']:
for path in build['parts']:
# print(path['path'])
path['path'] = path['path'].replace("..", "https://Jason2866.github.io/Tasmota-specials")
# print(data)
j = json.dumps(data,indent=4)
f = open(outfile,"w")
f.write(j)
f.close()
def getManifestEntry(manifest):
entry = {}
with open(manifest) as json_file:
data = json.load(json_file)
entry['path'] = "https://Jason2866.github.io/Tasmota-specials/" + manifest
entry['name'] = data['name']
entry['chipFamilies'] = []
for build in data['builds']:
entry['chipFamilies'].append(build['chipFamily'])
return entry
def main(args):
path_manifests = path.join('manifest')
path_manifests_ext = path.join('manifest_ext')
if not path.exists(path_manifests):
print("No manifest folder, exiting ...")
return -1
files = listdir(path_manifests)
if len(files) == 0:
print("Empty manifest folder, exiting ...")
return -1
if path.exists(path_manifests_ext):
m_e_files = listdir(path_manifests_ext)
# for file in m_e_files:
# remove(file)
else:
mkdir(path_manifests_ext)
output = {}
for file in files:
# create absolute path-version of each manifest file in /manifest_ext
convertJSON(path.join(path_manifests,file),path.join(path_manifests_ext,file))
line = file.split('.')
if len(line) != 4:
print("Incompatible path name, ignoring file:",file)
continue
# print(line[1])
if line[0] not in output:
output[line[0]] = [[],[],[],[],[],[]]
if line[1] == "tasmota":
output[line[0]][0].insert(0,getManifestEntry(path.join(path_manifests_ext,file))) # vanilla first
continue
elif line[1] == "tasmota32":
output[line[0]][1].insert(0,getManifestEntry(path.join(path_manifests_ext,file)))
continue
else: #solo1,4M,...
output[line[0]][2].append(getManifestEntry(path.join(path_manifests_ext,file)))
continue
name_components = line[1].split('-')
if name_components[0] == "tasmota":
if len(name_components[1]) and name_components[1].isupper():
output[line[0]][1].append(getManifestEntry(path.join(path_manifests_ext,file))) # language versions last
continue
output[line[0]][0].append(getManifestEntry(path.join(path_manifests_ext,file)))
continue
elif name_components[0] == "tasmota32":
if len(name_components[1]) and name_components[1].isupper():
output[line[0]][3].append(getManifestEntry(path.join(path_manifests_ext,file))) # language versions last
continue
output[line[0]][2].append(getManifestEntry(path.join(path_manifests_ext,file)))
continue
else: #solo1,4M,...
if len(name_components[1]) and name_components[1].isupper():
output[line[0]][5].append(getManifestEntry(path.join(path_manifests_ext,file))) # language versions last
continue
output[line[0]][4].append(getManifestEntry(path.join(path_manifests_ext,file)))
# print(output)
for section in output:
merged = sorted(output[section][0],key=lambda d: d['name']) + sorted(output[section][1],key=lambda d: d['name']) + sorted(output[section][2],key=lambda d: d['name']) + sorted(output[section][3],key=lambda d: d['name']) + sorted(output[section][4],key=lambda d: d['name']) + sorted(output[section][5],key=lambda d: d['name'])
output[section] = merged
#release = output.pop("release")
#development = output.pop("development")
unofficial = output.pop("unofficial")
final_json = {}
#final_json["release"] = release
#final_json["development"] = development
final_json["unofficial"] = unofficial
for key in output:
final_json[key] = output[key] # just in case we have another section in the future
print(final_json)
j = json.dumps(final_json,indent=4)
f = open("manifests.json", "w")
f.write(j)
f.close()
# intermediate version with double output (DEPRECATED)
f = open("manifests_new.json", "w")
f.write(j)
f.close()
# end deprecated version
if __name__ == '__main__':
sys.exit(main(sys.argv))
# end if