Monitor return codes of calls to convert and unpaper

...and handle the failures nicely.  Addresses #303.
This commit is contained in:
Daniel Quinn 2018-02-18 16:02:27 +00:00
parent 8e9d5caa37
commit ea6d040809
2 changed files with 7 additions and 5 deletions

View File

@ -117,10 +117,10 @@ class Consumer:
)
parsed_document = parser_class(doc)
thumbnail = parsed_document.get_thumbnail()
date = parsed_document.get_date()
try:
thumbnail = parsed_document.get_thumbnail()
date = parsed_document.get_date()
document = self._store(
parsed_document.get_text(),
doc,

View File

@ -233,13 +233,15 @@ def run_convert(*args):
if settings.CONVERT_TMPDIR:
environment["MAGICK_TMPDIR"] = settings.CONVERT_TMPDIR
subprocess.Popen(args, env=environment).wait()
if not subprocess.Popen(args, env=environment).wait() == 0:
raise ParseError("Convert failed at {}".format(args))
def run_unpaper(args):
unpaper, pnm = args
subprocess.Popen(
(unpaper, pnm, pnm.replace(".pnm", ".unpaper.pnm"))).wait()
command_args = unpaper, pnm, pnm.replace(".pnm", ".unpaper.pnm")
if not subprocess.Popen(command_args).wait() == 0:
raise ParseError("Unpaper failed at {}".format(command_args))
def strip_excess_whitespace(text):