-
-
Notifications
You must be signed in to change notification settings - Fork 762
Expand file tree
/
Copy pathcheck.py
More file actions
executable file
·47 lines (42 loc) · 1.37 KB
/
check.py
File metadata and controls
executable file
·47 lines (42 loc) · 1.37 KB
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
#!/usr/bin/env python3
import os
import re
import sys
from glob import glob
error = False
MYDIR = os.path.dirname(__file__)
EXPECTED_PREFIX_RE = re.compile(r"messages-(\w+)(?:-.*)?\.proto")
WITHOUT_PREFIX = [
"Bitcoin",
"Bootloader",
"Common",
"Crypto",
"Definitions",
"Management",
]
# Checking all protobuf files for their `enum` and `message` declarations
# and making sure their names start with expected prefix
for fn in sorted(glob(os.path.join(MYDIR, "messages-*.proto"))):
with open(fn, "rt") as f:
filename = EXPECTED_PREFIX_RE.search(fn)
assert filename
prefix = filename.group(1).capitalize()
if prefix in WITHOUT_PREFIX:
continue
if prefix == "Nem":
prefix = "NEM"
elif prefix == "Webauthn":
prefix = "WebAuthn"
for line in f:
line = line.strip().split(" ")
if line[0] not in ("enum", "message"):
continue
expected_prefixes = (prefix, f"Debug{prefix}")
if not line[1].startswith(expected_prefixes):
print("ERROR: protobuf message does not start with expected prefix")
print(f" file: {fn}")
print(f" message: {line[1]}")
print(f" expected prefixes: {expected_prefixes}")
error = True
if error:
sys.exit(1)