Normalize wads arriving in zips wrapping dirs.

Most wads put all the files directly in the top level of the zip; some
instead include a top level directory and put everything in that.  We
create our own directory to extract into to avoid polluting the PWAD
directory, and then in the latter case move everything up a level and
then remove the wrapping directory.
This commit is contained in:
yrriban 2026-08-02 13:58:01 -04:00
parent cbf2ec2ca6
commit 639389e38f

View file

@ -29,9 +29,16 @@ class Fetch(doomcc.config.Base):
)
wad = reply["content"]["filename"][0:-4]
pwadpath = self.pwads.joinpath(wad)
with urllib.request.urlopen(rpath) as response:
z = zipfile.ZipFile(io.BytesIO(response.read()))
z.extractall(path=self.pwads.joinpath(wad))
z.extractall(path=pwadpath)
contents = list(pwadpath.glob('*'))
if len(contents) == 1 and contents[0].is_dir():
for wc in contents[0].glob('*'):
wc.rename(pwadpath.joinpath(wc.name))
contents[0].rmdir()
# TODO: explicit error handling. Let users choose when >1 result.
def search_idgames(self, wad):