forked from droidian-devices/devices.droidian.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
schema_validation.py
106 lines (104 loc) · 2.48 KB
/
schema_validation.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
import yaml
import os
from schema import Optional,Or, Schema, SchemaError
device_schema = Schema({
'manufacturer': str,
'name': str,
'codename': str,
'support': Or("community", "official"),
'device_type': str,
'halium_version': int,
'fastboot_mode': str,
'recovery_mode': str,
'ab_slot': bool,
'api_version': str,
'arch': str,
Optional('notes_before_you_start'): Or([
{
Optional('title'): Or(None, str),
'text': Or(None, str),
}
], None),
'droidian_release': Or(None, str),
'channel':Or("stable","nightly"),
'droidian_required_build': {
'rootfs_link': Or(None, str),
'devtools_link': Or(None, str),
},
'android': {
'link': Or(None, str),
'text': Or(None, str),
'filename': Or(None, str),
},
'vendor_zip': {
'link': Or(None, str),
'text': Or(None, str),
'filename': Or(None, str),
},
'vendor_image': {
'link': Or(None, str),
'text': Or(None, str),
'filename': Or(None, str),
},
'boot': {
'link': Or(None, str),
'text': Or(None, str),
'filename': Or(None, str),
},
'dtbo': {
'link': Or(None, str),
'text': Or(None, str),
'filename': Or(None, str),
},
'recovery': {
'name': str,
'link': str,
'text': str,
'filename': str,
'must_flash': Or(None, bool),
},
'adaptation': {
'link': Or(None, str),
'text': Or(None, str),
'filename': Or(None, str),
},
'statuspage': Or(None, str),
'contact': Or({
'text': Or(None, str),
'link': Or(None, str),
}, None),
'credit': [
{
'name': Or(None, str),
'link': Or(None, str),
},
],
'command':
Or([
Or(None, str)
], None),
'notes': Or([
{
'title': Or(None, str),
'text': Or(None, str),
}
], None),
'port_status': [
{
'category_name': str,
'features': [{
'id': str,
'value': Or("+", "-", "~", "?", "x")
}]
}
]
})
def validate_file(file):
try:
device_schema.validate(file)
print(f"Device configuration is valid for {file['codename']}.")
return True
except SchemaError as se:
print('Error in', file['codename'])
print(se)
return False