forked from flathub-infra/flatpak-builder-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
validator.py
69 lines (62 loc) · 2.34 KB
/
validator.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 argparse
import json
from typing import Any, Sequence
known_exceptions = {
"appid-code-hosting-too-few-components",
"appid-ends-with-lowercase-desktop",
"appid-uses-code-hosting-domain",
"appstream-failed-validation",
"appstream-id-mismatch-flatpak-id",
"appstream-missing-developer-name",
"desktop-file-failed-validation",
"finish-args-arbitrary-autostart-access",
"finish-args-arbitrary-dbus-access",
"finish-args-arbitrary-xdg-data-access",
"finish-args-contains-both-x11-and-wayland",
"finish-args-flatpak-spawn-access",
"finish-args-not-defined",
"finish-args-unnecessary-xdg-cache-access",
"finish-args-unnecessary-xdg-config-access",
"finish-args-unnecessary-xdg-data-access",
"finish-args-wildcard-kde-own-name",
"flathub-json-modified-publish-delay",
"finish-args-wildcard-kde-talk-name",
}
def check_duplicates(
pairs: list[tuple[str, Any]],
) -> dict[str, Any]:
d = {}
for key, val in pairs:
if key in d:
raise ValueError(f"Duplicate key(s) found: {key}")
else:
d[key] = val
return d
def main(argv: Sequence[str] | None = None) -> int:
parser = argparse.ArgumentParser()
parser.add_argument("filenames", nargs="*", help="Input filenames")
args = parser.parse_args(argv)
exit_code = 0
for filename in args.filenames:
with open(filename, "r") as f:
try:
data = json.load(f, object_pairs_hook=check_duplicates)
found_exceptions = {
j for i in data.values() for j in i if not j.startswith("module-")
} - {
"*",
"appid-filename-mismatch",
"flathub-json-deprecated-i386-arch-included",
"toplevel-no-command",
"flathub-json-skip-appstream-check",
"appstream-missing-appinfo-file",
}
if not found_exceptions.issubset(known_exceptions):
print("Exception not found in known exceptions list", found_exceptions - known_exceptions)
exit_code = 1
except ValueError as err:
print(f"{filename}: Failed to decode: {err}")
exit_code = 1
return exit_code
if __name__ == "__main__":
raise SystemExit(main())