restore skip actions with download archive

This commit is contained in:
Mike Fährmann
2018-02-12 16:56:45 +01:00
parent c0dd922c13
commit 4d2fadfb6f
2 changed files with 23 additions and 25 deletions

View File

@@ -160,8 +160,7 @@ class DownloadJob(Job):
# prepare download # prepare download
self.pathfmt.set_keywords(keywords) self.pathfmt.set_keywords(keywords)
if self.pathfmt.exists() or \ if self.pathfmt.exists(self.archive):
self.archive and self.archive.check(keywords):
self.out.skip(self.pathfmt.path) self.out.skip(self.pathfmt.path)
return return
@@ -172,7 +171,7 @@ class DownloadJob(Job):
if not self.get_downloader(url).download(url, self.pathfmt): if not self.get_downloader(url).download(url, self.pathfmt):
# use fallback URLs if available # use fallback URLs if available
for num, url in enumerate(fallback or [], 1): for num, url in enumerate(fallback or (), 1):
self.log.info("Trying fallback URL #%d", num) self.log.info("Trying fallback URL #%d", num)
if self.get_downloader(url).download(url, self.pathfmt): if self.get_downloader(url).download(url, self.pathfmt):
break break
@@ -182,7 +181,7 @@ class DownloadJob(Job):
"Failed to download %s", self.pathfmt.filename) "Failed to download %s", self.pathfmt.filename)
return return
# download successful # download succeeded
if self.archive: if self.archive:
self.archive.add() self.archive.add()

View File

@@ -362,22 +362,31 @@ class PathFormat():
if os.altsep: if os.altsep:
self.basedirectory = self.basedirectory.replace(os.altsep, os.sep) self.basedirectory = self.basedirectory.replace(os.altsep, os.sep)
skipmode = extractor.config("skip", True) skip = extractor.config("skip", True)
if skipmode == "abort": if skip:
self.exists = self._exists_abort if skip == "abort":
elif skipmode == "exit": self._skipexc = exception.StopExtraction
self.exists = self._exists_exit elif skip == "exit":
elif not skipmode: self._skipexc = exit
self.exists = lambda: False else:
self._skipexc = None
else:
self.exists = lambda x=None: False
def open(self, mode="wb"): def open(self, mode="wb"):
"""Open file and return a corresponding file object""" """Open file and return a corresponding file object"""
return open(self.partpath or self.realpath, mode) return open(self.partpath or self.realpath, mode)
def exists(self): def exists(self, archive=None):
"""Return True if 'path' is complete and refers to an existing path""" if (self.has_extension and os.path.exists(self.realpath) or
if self.has_extension: archive and archive.check(self.keywords)):
return os.path.exists(self.realpath) if self._skipexc:
raise self._skipexc()
if not self.has_extension:
self.set_extension("")
if self.path[-1] == ".":
self.path = self.path[:-1]
return True
return False return False
def set_directory(self, keywords): def set_directory(self, keywords):
@@ -462,16 +471,6 @@ class PathFormat():
shutil.copyfile(self.partpath, self.realpath) shutil.copyfile(self.partpath, self.realpath)
os.unlink(self.partpath) os.unlink(self.partpath)
def _exists_abort(self):
if self.has_extension and os.path.exists(self.realpath):
raise exception.StopExtraction()
return False
def _exists_exit(self):
if self.has_extension and os.path.exists(self.realpath):
exit()
return False
@staticmethod @staticmethod
def adjust_path(path): def adjust_path(path):
"""Enable longer-than-260-character paths on windows""" """Enable longer-than-260-character paths on windows"""