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:
parent
cbf2ec2ca6
commit
639389e38f
1 changed files with 8 additions and 1 deletions
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue