]> git.proxmox.com Git - mirror_linux-firmware.git/blame - check_whence.py
check_whence: error on duplicate file entries
[mirror_linux-firmware.git] / check_whence.py
CommitLineData
6de0c03f 1#!/usr/bin/python3
7d887360
BH
2
3import os, re, sys
94cb0a68 4from io import open
7d887360
BH
5
6def 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
31def 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:
36 yield match.group(1).replace("\ ", " ")
37 continue
38
7d887360
BH
39def list_git():
40 with os.popen('git ls-files') as git_files:
41 for line in git_files:
42 yield line.rstrip('\n')
43
44def 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
05183b7b
EV
54 for name in set(fw for fw in whence_files if whence_files.count(fw) > 1):
55 sys.stderr.write('E: %s listed in WHENCE twice\n' % name)
56 ret = 1
57
7d887360
BH
58 for name in sorted(list(known_files - git_files)):
59 sys.stderr.write('E: %s listed in WHENCE does not exist\n' % name)
7fa32bcc 60 ret = 1
7d887360
BH
61
62 for name in sorted(list(git_files - known_files)):
63 # Ignore subdirectory changelogs and GPG detached signatures
64 if (name.endswith('/ChangeLog') or
65 (name.endswith('.asc') and name[:-4] in known_files)):
66 continue
67
68 # Ignore unknown files in known directories
69 for prefix in known_prefixes:
70 if name.startswith(prefix):
71 break
72 else:
73 sys.stderr.write('E: %s not listed in WHENCE\n' % name)
7fa32bcc
BN
74 ret = 1
75 return ret
7d887360
BH
76
77if __name__ == '__main__':
7fa32bcc 78 sys.exit(main())