]>
git.proxmox.com Git - mirror_linux-firmware.git/blob - check_whence.py
7 with
open('WHENCE', encoding
='utf-8') as whence
:
9 match
= re
.match(r
'(?:File|Source):\s*"(.*)"', line
)
13 match
= re
.match(r
'(?:File|Source):\s*(\S*)', line
)
17 match
= re
.match(r
'Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n',
21 for name
in re
.split(r
', | and ', match
.group(1)):
25 # Just one word - may or may not be a filename
26 if not re
.search(r
'unknown|distributable', match
.group(2),
31 def list_whence_files():
32 with
open('WHENCE', encoding
='utf-8') as whence
:
34 match
= re
.match(r
'File:\s*(.*)', line
)
36 yield match
.group(1).replace("\ ", " ").replace("\"", "")
39 def list_links_list():
40 with
open('WHENCE', encoding
='utf-8') as whence
:
42 match
= re
.match(r
'Link:\s*(.*)', line
)
44 linkname
, target
= match
.group(1).split("->")
46 linkname
= linkname
.strip().replace("\ ", " ").replace("\"", "")
47 target
= target
.strip().replace("\ ", " ").replace("\"", "")
49 # Link target is relative to the link
50 target
= os
.path
.join(os
.path
.dirname(linkname
), target
)
51 target
= os
.path
.normpath(target
)
53 yield (linkname
, target
)
57 with os
.popen('git ls-files') as git_files
:
58 for line
in git_files
:
59 yield line
.rstrip('\n')
63 whence_list
= list(list_whence())
64 whence_files
= list(list_whence_files())
65 links_list
= list(list_links_list())
66 known_files
= set(name
for name
in whence_list
if not name
.endswith('/')) | \
67 set(['check_whence.py', 'configure', 'Makefile',
68 'README', 'copy-firmware.sh', 'WHENCE'])
69 known_prefixes
= set(name
for name
in whence_list
if name
.endswith('/'))
70 git_files
= set(list_git())
72 for name
in set(name
for name
in whence_files
if name
.endswith('/')):
73 sys
.stderr
.write('E: %s listed in WHENCE as File, but is directory\n' %
77 for name
in set(fw
for fw
in whence_files
if whence_files
.count(fw
) > 1):
78 sys
.stderr
.write('E: %s listed in WHENCE twice\n' % name
)
81 for name
in set(link
for link
in whence_files
if os
.path
.islink(link
)):
82 sys
.stderr
.write('E: %s listed in WHENCE as File, but is a symlink\n' %
86 for name
in set(link
[0] for link
in links_list
if os
.path
.islink(link
[0])):
87 sys
.stderr
.write('E: %s listed in WHENCE as Link, is in tree\n' % name
)
90 for name
in sorted(list(known_files
- git_files
)):
91 sys
.stderr
.write('E: %s listed in WHENCE does not exist\n' % name
)
94 # A link can point to another link, or to a file...
95 valid_targets
= set(link
[0] for link
in links_list
) | git_files
97 # ... or to a directory
98 for target
in set(valid_targets
):
101 dirname
= os
.path
.dirname(dirname
)
104 valid_targets
.add(dirname
)
106 for name
, target
in sorted(links_list
):
107 if target
not in valid_targets
:
108 sys
.stderr
.write('E: target %s of link %s in WHENCE'
109 ' does not exist\n' % (target
, name
))
112 for name
in sorted(list(git_files
- known_files
)):
113 # Ignore subdirectory changelogs and GPG detached signatures
114 if (name
.endswith('/ChangeLog') or
115 (name
.endswith('.asc') and name
[:-4] in known_files
)):
118 # Ignore unknown files in known directories
119 for prefix
in known_prefixes
:
120 if name
.startswith(prefix
):
123 sys
.stderr
.write('E: %s not listed in WHENCE\n' % name
)
127 if __name__
== '__main__':