forked from repology/repology-updater
-
Notifications
You must be signed in to change notification settings - Fork 0
/
repology-schemacheck.py
executable file
·224 lines (200 loc) · 5.6 KB
/
repology-schemacheck.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env python3
#
# Copyright (C) 2016-2017 Dmitry Marakasov <amdmi3@amdmi3.ru>
#
# This file is part of repology
#
# repology is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# repology is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with repology. If not, see <http://www.gnu.org/licenses/>.
import argparse
import os
from datetime import date
from voluptuous import Any, MultipleInvalid, Required, Schema, Url
import yaml
families = [
'alpine',
'anitya',
'aosc',
'arch',
'centos',
'chocolatey',
'cpan',
'cran',
'crates_io',
'crux',
'debuntu',
'distrowatch',
'fdroid',
'fedora',
'freebsd',
'freshcode',
'gentoo',
'gobolinux',
'guix',
'hackage',
'haikuports',
'homebrew',
'kaos',
'libregamewiki',
'macports',
'mageia',
'msys2',
'nix',
'openbsd',
'openindiana',
'openmandriva',
'opensuse',
'openwrt',
'pclinuxos',
'pkgsrc',
'pypi',
'ravenports',
'rosa',
'rubygems',
'rudix',
'scoop',
'sisyphus',
'slackbuilds',
'snap',
'vcpkg',
'wikidata',
'yacp',
]
rulesets = families + [
'antix',
'aur',
'deb_multimedia',
'deepin',
'hyperbola',
'maemo',
'manjaro',
'pardus',
'parrot',
]
schemas = {
'repos': [
{
Required('name'): str,
'sortname': str,
'singular': str,
Required('type'): Any('repository', 'site', 'modules'),
Required('desc'): str,
Required('family'): Any(*families),
'ruleset': Any(Any(*rulesets), [Any(*rulesets)]), # XXX: make required
'color': str,
'valid_till': date,
'default_maintainer': str,
Required('minpackages'): int,
Required('sources'): [
{
Required('name'): Any(str, [str]),
Required('fetcher'): str,
Required('parser'): str,
'url': str, # not Url(), as there may be rsync or cvs addresses
# git fetcher args
'branch': str,
'subrepo': str,
'sparse_checkout': [str],
# some common fetcher args
'fetch_timeout': int,
# arch parser
'allowed_archs': [str],
# file fetcher
'compression': Any('xz', 'bz2', 'gz'),
'post': {str: str},
'headers': {str: str},
'nocache': bool,
}
],
'shadow': bool,
'repolinks': [
{
Required('desc'): str,
Required('url'): Url(),
}
],
'packagelinks': [
{
Required('desc'): str,
Required('url'): Url(),
}
],
'tags': [
str
]
}
],
'rules': [
{
'name': Any(str, [str]),
'namepat': str,
'ver': Any(str, [str]),
'verpat': str,
'wwwpart': Any(str, [str]),
'wwwpat': str,
'family': Any(Any(*families), [Any(*families)]), # XXX: legacy; remove after rules converted to ruleset
'ruleset': Any(Any(*rulesets), [Any(*rulesets)]),
'noruleset': Any(Any(*rulesets), [Any(*rulesets)]),
'category': Any(str, [str]),
'verlonger': int,
'vergt': str,
'verge': str,
'verlt': str,
'verle': str,
'flag': str,
'noflag': str,
'setname': str,
'setver': str,
'addflavor': Any(bool, str, [str]),
'resetflavors': bool,
'remove': bool,
'ignore': bool,
'devel': bool,
'p_is_patch': bool,
'any_is_patch': bool,
'outdated': bool,
'legacy': bool,
'incorrect': bool,
'untrusted': bool,
'noscheme': bool,
'snapshot': bool,
'successor': bool,
'rolling': bool,
'addflag': str,
'last': bool,
'tolowername': bool,
'replaceinname': dict,
'warning': str,
}
]
}
def GetYaml(path):
with open(path) as yamlfile:
return yaml.safe_load(yamlfile)
def ParseArguments():
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-s', '--schema', choices=schemas.keys(), required=True, help='schema to use')
parser.add_argument('files', metavar='file', nargs='*', help='files to check')
return parser.parse_args()
def Main():
options = ParseArguments()
errors = 0
for path in options.files:
try:
Schema(schemas[options.schema])(GetYaml(path))
except MultipleInvalid as e:
print('Bad schema for {}: {}'.format(path, str(e)))
errors += 1
return 1 if errors else 0
if __name__ == '__main__':
os.sys.exit(Main())