]>
git.proxmox.com Git - mirror_linux-firmware.git/blob - check_whence.py
8 with
open("WHENCE", encoding
="utf-8") as whence
:
10 match
= re
.match(r
'(?:RawFile|File|Source):\s*"(.*)"', line
)
14 match
= re
.match(r
"(?:RawFile|File|Source):\s*(\S*)", line
)
19 r
"Licen[cs]e: (?:.*\bSee (.*) for details\.?|(\S*))\n", line
23 for name
in re
.split(r
", | and ", match
.group(1)):
27 # Just one word - may or may not be a filename
29 r
"unknown|distributable", match
.group(2), re
.IGNORECASE
35 def list_whence_files():
36 with
open("WHENCE", encoding
="utf-8") as whence
:
38 match
= re
.match(r
"(?:RawFile|File):\s*(.*)", line
)
40 yield match
.group(1).replace("\ ", " ").replace('"', "")
44 def list_links_list():
45 with
open("WHENCE", encoding
="utf-8") as whence
:
47 match
= re
.match(r
"Link:\s*(.*)", line
)
49 linkname
, target
= match
.group(1).split("->")
51 linkname
= linkname
.strip().replace("\ ", " ").replace('"', "")
52 target
= target
.strip().replace("\ ", " ").replace('"', "")
54 # Link target is relative to the link
55 target
= os
.path
.join(os
.path
.dirname(linkname
), target
)
56 target
= os
.path
.normpath(target
)
58 yield (linkname
, target
)
63 with os
.popen("git ls-files") as git_files
:
64 for line
in git_files
:
65 yield line
.rstrip("\n")
70 whence_list
= list(list_whence())
71 whence_files
= list(list_whence_files())
72 links_list
= list(list_links_list())
73 known_files
= set(name
for name
in whence_list
if not name
.endswith("/")) |
set(
78 ".pre-commit-config.yaml",
87 "contrib/templates/debian.changelog",
88 "contrib/templates/debian.control",
89 "contrib/templates/debian.copyright",
90 "contrib/templates/rpm.spec",
93 known_prefixes
= set(name
for name
in whence_list
if name
.endswith("/"))
94 git_files
= set(list_git())
96 for name
in set(name
for name
in whence_files
if name
.endswith("/")):
97 sys
.stderr
.write("E: %s listed in WHENCE as File, but is directory\n" % name
)
100 for name
in set(fw
for fw
in whence_files
if whence_files
.count(fw
) > 1):
101 sys
.stderr
.write("E: %s listed in WHENCE twice\n" % name
)
104 for name
in set(link
for link
in whence_files
if os
.path
.islink(link
)):
105 sys
.stderr
.write("E: %s listed in WHENCE as File, but is a symlink\n" % name
)
108 for name
in set(link
[0] for link
in links_list
if os
.path
.islink(link
[0])):
109 sys
.stderr
.write("E: %s listed in WHENCE as Link, is in tree\n" % name
)
112 for name
in sorted(list(known_files
- git_files
)):
113 sys
.stderr
.write("E: %s listed in WHENCE does not exist\n" % name
)
116 # A link can point to another link, or to a file...
117 valid_targets
= set(link
[0] for link
in links_list
) | git_files
119 # ... or to a directory
120 for target
in set(valid_targets
):
123 dirname
= os
.path
.dirname(dirname
)
126 valid_targets
.add(dirname
)
128 for name
, target
in sorted(links_list
):
129 if target
not in valid_targets
:
131 "E: target %s of link %s in WHENCE" " does not exist\n" % (target
, name
)
135 for name
in sorted(list(git_files
- known_files
)):
136 # Ignore subdirectory changelogs and GPG detached signatures
137 if name
.endswith("/ChangeLog") or (
138 name
.endswith(".asc") and name
[:-4] in known_files
142 # Ignore unknown files in known directories
143 for prefix
in known_prefixes
:
144 if name
.startswith(prefix
):
147 sys
.stderr
.write("E: %s not listed in WHENCE\n" % name
)
152 if __name__
== "__main__":