include failed downloads and child extractors in exit status

This commit is contained in:
Mike Fährmann
2019-10-29 15:56:54 +01:00
parent 322c2e7ed4
commit 5af291ba5c
2 changed files with 9 additions and 8 deletions

View File

@@ -247,7 +247,7 @@ def main():
retval |= jobtype(url).run() retval |= jobtype(url).run()
except exception.NoExtractorError: except exception.NoExtractorError:
log.error("No suitable extractor found for '%s'", url) log.error("No suitable extractor found for '%s'", url)
retval |= 128 retval |= 64
return retval return retval
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@@ -29,6 +29,7 @@ class Job():
extr.log.job = self extr.log.job = self
extr.log.debug("Using %s for '%s'", extr.__class__.__name__, extr.url) extr.log.debug("Using %s for '%s'", extr.__class__.__name__, extr.url)
self.status = 0
self.pred_url = self._prepare_predicates("image", True) self.pred_url = self._prepare_predicates("image", True)
self.pred_queue = self._prepare_predicates("chapter", False) self.pred_queue = self._prepare_predicates("chapter", False)
@@ -49,15 +50,15 @@ class Job():
except exception.StopExtraction as exc: except exception.StopExtraction as exc:
if exc.message: if exc.message:
log.error(exc.message) log.error(exc.message)
return exc.code self.status |= exc.code
except exception.GalleryDLException as exc: except exception.GalleryDLException as exc:
log.error("%s: %s", exc.__class__.__name__, exc) log.error("%s: %s", exc.__class__.__name__, exc)
return exc.code self.status |= exc.code
except OSError as exc: except OSError as exc:
log.error("Unable to download data: %s: %s", log.error("Unable to download data: %s: %s",
exc.__class__.__name__, exc) exc.__class__.__name__, exc)
log.debug("", exc_info=True) log.debug("", exc_info=True)
return 128 self.status |= 128
except Exception as exc: except Exception as exc:
log.error(("An unexpected error occurred: %s - %s. " log.error(("An unexpected error occurred: %s - %s. "
"Please run gallery-dl again with the --verbose flag, " "Please run gallery-dl again with the --verbose flag, "
@@ -65,11 +66,10 @@ class Job():
"https://github.com/mikf/gallery-dl/issues ."), "https://github.com/mikf/gallery-dl/issues ."),
exc.__class__.__name__, exc) exc.__class__.__name__, exc)
log.debug("", exc_info=True) log.debug("", exc_info=True)
return 1 self.status |= 1
else:
return 0
finally: finally:
self.handle_finalize() self.handle_finalize()
return self.status
def dispatch(self, msg): def dispatch(self, msg):
"""Call the appropriate message handler""" """Call the appropriate message handler"""
@@ -207,6 +207,7 @@ class DownloadJob(Job):
break break
else: else:
# download failed # download failed
self.status |= 4
self.log.error("Failed to download %s", self.log.error("Failed to download %s",
pathfmt.filename or url) pathfmt.filename or url)
return return
@@ -249,7 +250,7 @@ class DownloadJob(Job):
else: else:
extr = extractor.find(url) extr = extractor.find(url)
if extr: if extr:
self.__class__(extr, self).run() self.status |= self.__class__(extr, self).run()
else: else:
self._write_unsupported(url) self._write_unsupported(url)