-
Notifications
You must be signed in to change notification settings - Fork 2
/
build_manifest_all.py
executable file
·153 lines (142 loc) · 5.34 KB
/
build_manifest_all.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
import json
import requests
from jsonschema import validate, ValidationError
schema_individual = {
"type": "object",
"properties": {
"name": {"type": "string"},
"maintainer": {"type": "string"},
"hostOperatingsystem": {
"type": "array",
"items": {"type": "string"}
},
"environment": {
"type": "array",
"items": {"type": "string"}
},
"hardware": {
"type": "object",
"properties": {
"chipVendor": {"type": "string"},
"manufacturer": {"type": "string"},
"specs": {
"type": "object",
"properties": {
"MCU": {"type": "string"},
"RAM": {"type": "string"},
"Flash": {"type": "string"},
"GPU": {"type": ["string", "null"]},
"Resolution": {"type": "string"},
"Display Size": {"type": "string"},
"Interface": {"type": "string"},
"Color Depth": {"type": "string"},
"Technology": {"type": "string"},
"DPI": {"type": "string"},
"Touch Pad": {"type": "string"}
},
"required": ["MCU", "RAM", "Flash"]
}
},
"required": ["chipVendor", "manufacturer", "specs"]
},
"description": {"type": "string"},
"shortDescription": {"type": "string"},
"urlToClone": {"type": "string"},
"logos": {
"type": "array",
"items": {"type": "string"}
},
"branches": {
"type": "array",
"items": {"type": "string"}
},
"settings": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {"type": "string"},
"label": {"type": "string"},
"options": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {"type": "string"},
"value": {"type": "string"},
"default": {"type": "string", "enum": ["true", "false"], "default": "false"}
},
"required": ["name", "value"]
}
},
"actions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"ifValue": {"type": "string"},
"toAppend": {"type": "string"},
"toReplace": {"type": "string"},
"newContent": {"type": "string"},
"filePath": {"type": "string"}
}
}
}
},
"required": ["type"]
}
}
},
"required": ["name", "maintainer", "hostOperatingsystem", "environment", "description", "shortDescription", "urlToClone", "logos", "branches", "settings"]
}
schema_whole = {
"type": "array",
"items": schema_individual
}
# Function to validate JSON against the schema
def validate_json(json_data, schema):
try:
validate(instance=json_data, schema=schema)
print("JSON is valid")
return True
except ValidationError as e:
print(f"JSON validation error: {e.message}")
if e.path:
print(f"Error location: {' -> '.join(map(str, e.path))}")
else:
print("Error location: Root of the document")
return False
# Function to fetch JSON content from a URL
def fetch_json(url):
response = requests.get(url)
response.raise_for_status() # Raise an exception for HTTP errors
return response.json()
# List to hold all the JSON content
all_json_data = []
# Read the file containing URLs to JSON files
with open('manifests', 'r') as file:
urls = file.readlines()
# Fetch and concatenate JSON data from each URL
for url in urls:
url = url.strip() # Remove any extra whitespace or newlines
if url: # Ensure the URL is not empty
print(f"Fetching {url}")
try:
json_data = fetch_json(url)
validate_json(json_data, schema_individual) # Validate each JSON fetched
all_json_data.append(json_data) # Append if valid
except requests.exceptions.RequestException as e:
print(f"Error fetching {url}: {e}")
except ValidationError as e:
print(f"Validation failed for {url}: {e.message}")
print("Validating the concatenated JSON")
valid = validate_json(all_json_data, schema_whole)
filename = "manifest_all_v1.1.0.json"
if valid:
# Save the concatenated JSON data to a new file
with open(filename, 'w') as outfile:
json.dump(all_json_data, outfile, indent=4)
print(f"All JSON data has been concatenated and saved to {filename}.")
else:
print("Error: the concatenated JSON is invalid")