]>
Commit | Line | Data |
---|---|---|
7d887360 BH |
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: | |
be15035d HG |
8 | match = re.match(r'(?:File|Link|Source):\s*"(.*)"', line) |
9 | if match: | |
10 | yield match.group(1) | |
11 | continue | |
7d887360 BH |
12 | match = re.match(r'(?:File|Link|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 | whence_list = list(list_whence()) | |
37 | known_files = set(name for name in whence_list if not name.endswith('/')) | \ | |
38 | set(['check_whence.py', 'configure', 'Makefile', | |
39 | 'README', 'WHENCE']) | |
40 | known_prefixes = set(name for name in whence_list if name.endswith('/')) | |
41 | git_files = set(list_git()) | |
42 | ||
43 | for name in sorted(list(known_files - git_files)): | |
44 | sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name) | |
45 | ||
46 | for name in sorted(list(git_files - known_files)): | |
47 | # Ignore subdirectory changelogs and GPG detached signatures | |
48 | if (name.endswith('/ChangeLog') or | |
49 | (name.endswith('.asc') and name[:-4] in known_files)): | |
50 | continue | |
51 | ||
52 | # Ignore unknown files in known directories | |
53 | for prefix in known_prefixes: | |
54 | if name.startswith(prefix): | |
55 | break | |
56 | else: | |
57 | sys.stderr.write('E: %s not listed in WHENCE\n' % name) | |
58 | ||
59 | if __name__ == '__main__': | |
60 | main() |