]>
Commit | Line | Data |
---|---|---|
6de0c03f | 1 | #!/usr/bin/python3 |
7d887360 BH |
2 | |
3 | import os, re, sys | |
94cb0a68 | 4 | from io import open |
7d887360 BH |
5 | |
6 | def list_whence(): | |
94cb0a68 | 7 | with open('WHENCE', encoding='utf-8') as whence: |
7d887360 | 8 | for line in whence: |
9cfefbd7 | 9 | match = re.match(r'(?:File|Source):\s*"(.*)"', line) |
be15035d HG |
10 | if match: |
11 | yield match.group(1) | |
12 | continue | |
9cfefbd7 | 13 | match = re.match(r'(?:File|Source):\s*(\S*)', line) |
7d887360 BH |
14 | if match: |
15 | yield match.group(1) | |
16 | continue | |
17 | match = re.match(r'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n', | |
18 | line) | |
19 | if match: | |
20 | if match.group(1): | |
21 | for name in re.split(r', | and ', match.group(1)): | |
22 | yield name | |
23 | continue | |
24 | if match.group(2): | |
25 | # Just one word - may or may not be a filename | |
26 | if not re.search(r'unknown|distributable', match.group(2), | |
27 | re.IGNORECASE): | |
28 | yield match.group(2) | |
29 | continue | |
30 | ||
05183b7b EV |
31 | def list_whence_files(): |
32 | with open('WHENCE', encoding='utf-8') as whence: | |
33 | for line in whence: | |
34 | match = re.match(r'File:\s*(.*)', line) | |
35 | if match: | |
4b539e7a | 36 | yield match.group(1).replace("\ ", " ").replace("\"", "") |
05183b7b EV |
37 | continue |
38 | ||
7d887360 BH |
39 | def list_git(): |
40 | with os.popen('git ls-files') as git_files: | |
41 | for line in git_files: | |
42 | yield line.rstrip('\n') | |
43 | ||
44 | def main(): | |
7fa32bcc | 45 | ret = 0 |
7d887360 | 46 | whence_list = list(list_whence()) |
05183b7b | 47 | whence_files = list(list_whence_files()) |
7d887360 BH |
48 | known_files = set(name for name in whence_list if not name.endswith('/')) | \ |
49 | set(['check_whence.py', 'configure', 'Makefile', | |
c0fb3d98 | 50 | 'README', 'copy-firmware.sh', 'WHENCE']) |
7d887360 BH |
51 | known_prefixes = set(name for name in whence_list if name.endswith('/')) |
52 | git_files = set(list_git()) | |
53 | ||
6c9e0ed5 EV |
54 | for name in set(name for name in whence_files if name.endswith('/')): |
55 | sys.stderr.write('E: %s listed in WHENCE as File, but is directory\n' % | |
56 | name) | |
57 | ret = 1 | |
58 | ||
05183b7b EV |
59 | for name in set(fw for fw in whence_files if whence_files.count(fw) > 1): |
60 | sys.stderr.write('E: %s listed in WHENCE twice\n' % name) | |
61 | ret = 1 | |
62 | ||
f2671b1f EV |
63 | for name in set(link for link in whence_files if os.path.islink(link)): |
64 | sys.stderr.write('E: %s listed in WHENCE as File, but is a symlink\n' % | |
65 | name) | |
66 | ret = 1 | |
67 | ||
7d887360 BH |
68 | for name in sorted(list(known_files - git_files)): |
69 | sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name) | |
7fa32bcc | 70 | ret = 1 |
7d887360 BH |
71 | |
72 | for name in sorted(list(git_files - known_files)): | |
73 | # Ignore subdirectory changelogs and GPG detached signatures | |
74 | if (name.endswith('/ChangeLog') or | |
75 | (name.endswith('.asc') and name[:-4] in known_files)): | |
76 | continue | |
77 | ||
78 | # Ignore unknown files in known directories | |
79 | for prefix in known_prefixes: | |
80 | if name.startswith(prefix): | |
81 | break | |
82 | else: | |
83 | sys.stderr.write('E: %s not listed in WHENCE\n' % name) | |
7fa32bcc BN |
84 | ret = 1 |
85 | return ret | |
7d887360 BH |
86 | |
87 | if __name__ == '__main__': | |
7fa32bcc | 88 | sys.exit(main()) |