blob: 04f41dfc5f9e5976b2031a435bbf5d2bd00056b6 (
plain)
1 #!/usr/bin/python
2
3 import os, re, sys
4
5 def list_whence():
6 with open('WHENCE') as whence:
7 for line in whence:
8 match = re.match(r'(?:File|Source):\s*"(.*)"', line)
9 if match:
10 yield match.group(1)
11 continue
12 match = re.match(r'(?:File|Source):\s*(\S*)', line)
13 if match:
14 yield match.group(1)
15 continue
16 match = re.match(r'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n',
17 line)
18 if match:
19 if match.group(1):
20 for name in re.split(r', | and ', match.group(1)):
21 yield name
22 continue
23 if match.group(2):
24 # Just one word - may or may not be a filename
25 if not re.search(r'unknown|distributable', match.group(2),
26 re.IGNORECASE):
27 yield match.group(2)
28 continue
29
30 def list_git():
31 with os.popen('git ls-files') as git_files:
32 for line in git_files:
33 yield line.rstrip('\n')
34
35 def main():
36 ret = 0
37 whence_list = list(list_whence())
38 known_files = set(name for name in whence_list if not name.endswith('/')) | \
39 set(['check_whence.py', 'configure', 'Makefile',
40 'README', 'copy-firmware.sh', 'WHENCE'])
41 known_prefixes = set(name for name in whence_list if name.endswith('/'))
42 git_files = set(list_git())
43
44 for name in sorted(list(known_files - git_files)):
45 sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
46 ret = 1
47
48 for name in sorted(list(git_files - known_files)):
49 # Ignore subdirectory changelogs and GPG detached signatures
50 if (name.endswith('/ChangeLog') or
51 (name.endswith('.asc') and name[:-4] in known_files)):
52 continue
53
54 # Ignore unknown files in known directories
55 for prefix in known_prefixes:
56 if name.startswith(prefix):
57 break
58 else:
59 sys.stderr.write('E: %s not listed in WHENCE\n' % name)
60 ret = 1
61 return ret
62
63 if __name__ == '__main__':
64 sys.exit(main())
|