]> git.proxmox.com Git - mirror_linux-firmware.git/blob - check_whence.py
Merge branch 'MSCC-PHYs' of https://github.com/QSchulz/linux-firmware
[mirror_linux-firmware.git] / check_whence.py
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|Link|Source):\s*(\S*)', line)
9 if match:
10 yield match.group(1)
11 continue
12 match = re.match(r'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n',
13 line)
14 if match:
15 if match.group(1):
16 for name in re.split(r', | and ', match.group(1)):
17 yield name
18 continue
19 if match.group(2):
20 # Just one word - may or may not be a filename
21 if not re.search(r'unknown|distributable', match.group(2),
22 re.IGNORECASE):
23 yield match.group(2)
24 continue
25
26 def list_git():
27 with os.popen('git ls-files') as git_files:
28 for line in git_files:
29 yield line.rstrip('\n')
30
31 def main():
32 whence_list = list(list_whence())
33 known_files = set(name for name in whence_list if not name.endswith('/')) | \
34 set(['check_whence.py', 'configure', 'Makefile',
35 'README', 'WHENCE'])
36 known_prefixes = set(name for name in whence_list if name.endswith('/'))
37 git_files = set(list_git())
38
39 for name in sorted(list(known_files - git_files)):
40 sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
41
42 for name in sorted(list(git_files - known_files)):
43 # Ignore subdirectory changelogs and GPG detached signatures
44 if (name.endswith('/ChangeLog') or
45 (name.endswith('.asc') and name[:-4] in known_files)):
46 continue
47
48 # Ignore unknown files in known directories
49 for prefix in known_prefixes:
50 if name.startswith(prefix):
51 break
52 else:
53 sys.stderr.write('E: %s not listed in WHENCE\n' % name)
54
55 if __name__ == '__main__':
56 main()