scripts/dl_cleanup: add support for subdirectories

Allow comparing subdirectories exactly like files.

Handle a corner case where the new subdirectory
has the same tarball inside of it
as the one that was downloaded
before a subdirectory for that package was established.

Signed-off-by: Michael Pratt <mcpratt@pm.me>
This commit is contained in:
Michael Pratt 2022-09-19 16:39:34 -04:00
parent 59db286814
commit da4609788d

View File

@ -149,15 +149,18 @@ class Entry:
self.fileext = "" self.fileext = ""
self.filenoext = "" self.filenoext = ""
for ext in extensions: if os.path.isdir(self.getPath()):
if filename.endswith(ext): self.filenoext = filename
filename = filename[0 : 0 - len(ext)]
self.filenoext = filename
self.fileext = ext
break
else: else:
print(self.filename, "has an unknown file-extension") for ext in extensions:
raise EntryParseError("ext") if filename.endswith(ext):
filename = filename[0 : 0 - len(ext)]
self.filenoext = filename
self.fileext = ext
break
else:
print(self.filename, "has an unknown file-extension")
raise EntryParseError("ext")
for (regex, parseVersion) in versionRegex: for (regex, parseVersion) in versionRegex:
match = regex.match(filename) match = regex.match(filename)
if match: if match:
@ -184,7 +187,10 @@ class Entry:
path = self.getPath() path = self.getPath()
print("Deleting", path) print("Deleting", path)
if not opt_dryrun: if not opt_dryrun:
os.unlink(path) if os.path.isdir(path):
shutil.rmtree(path)
else:
os.unlink(path)
def deleteBuildDir(self): def deleteBuildDir(self):
paths = self.getBuildPaths() paths = self.getBuildPaths()
@ -301,6 +307,9 @@ def main(argv):
lastVersion = None lastVersion = None
versions = progmap[prog] versions = progmap[prog]
for version in versions: for version in versions:
if lastVersion:
if os.path.isdir(lastVersion.getPath()) and not os.path.isdir(version.getPath()):
continue
if lastVersion is None or version >= lastVersion: if lastVersion is None or version >= lastVersion:
lastVersion = version lastVersion = version
if lastVersion: if lastVersion: