-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgenerate.py
69 lines (50 loc) · 2.06 KB
/
generate.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
import os, json
URL_BASE = "http://raw.githubusercontent.com/matthuisman/pinn-os/master/{folder}/{file}"
OUTPUT = "os_list_v3.json"
IGNORES = ['hassio_RPi3']
MAP = {
"os_info": "os.json",
"partitions_info": "partitions.json",
"partition_setup": "partition_setup.sh",
"icon": "{folder}.png",
"marketing_info": "marketing.tar",
}
abspath = os.path.abspath(__file__)
dname = os.path.dirname(abspath)
DATA = {'os_list': []}
for folder in os.listdir(dname):
if folder in IGNORES:
continue
folder_path = os.path.join(dname, folder)
if not os.path.isdir(folder_path):
continue
files = os.listdir(folder_path)
if "os.json" not in files and "os_list.json" not in files:
continue
system = {}
os_file = os.path.join(folder_path, "os.json")
if os.path.exists(os_file):
with open(os.path.join(folder_path, "os.json"), "r", encoding='utf8') as f:
system.update(json.loads(f.read()))
partitions_file = os.path.join(folder_path, "partitions.json")
if os.path.exists(partitions_file):
with open(partitions_file, "r", encoding='utf8') as f:
partitions = json.loads(f.read())['partitions']
system['nominal_size'] = 0
for partition in partitions:
system['nominal_size'] += int(partition.get("partition_size_nominal", 0))
system['os_name'] = system.pop('name', None)
for key in MAP:
file_name = MAP[key].format(folder=folder)
if file_name in files:
system[key] = URL_BASE.format(folder=folder, file=file_name)
# else:
# print("{folder} missing {file}".format(folder=folder, file=file_name))
if "os_list.json" in files:
with open(os.path.join(folder_path, "os_list.json"), "r", encoding='utf8') as f:
system.update(json.loads(f.read()))
system.pop('supported_hex_revisions', None)
DATA['os_list'].append(system)
with open(OUTPUT, 'w', encoding='utf8') as f:
f.write(json.dumps(DATA, sort_keys=True, indent=4, separators=(',', ': '), ensure_ascii=False))
input("OK!")