Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 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: |
Thierry Reding | 016a2ec | 2019-09-30 13:17:04 +0200 | [diff] [blame] | 8 | match = re.match(r'(?:File|Source):\s*"(.*)"', line) |
Hans de Goede | 026bbcf | 2018-12-13 17:35:11 +0100 | [diff] [blame] | 9 | if match: |
| 10 | yield match.group(1) |
| 11 | continue |
Thierry Reding | 016a2ec | 2019-09-30 13:17:04 +0200 | [diff] [blame] | 12 | match = re.match(r'(?:File|Source):\s*(\S*)', line) |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 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', |
Josh Boyer | 95d22ac | 2019-08-21 08:03:43 -0400 | [diff] [blame] | 39 | 'README', 'copy-firmware.sh', 'WHENCE']) |
Ben Hutchings | 746efa1 | 2016-09-18 01:44:04 +0100 | [diff] [blame] | 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() |