This commit is contained in:
Daniel Quinn 2016-02-20 22:30:01 +00:00
parent 3a8755e4c8
commit 51b19f4c19

View File

@ -128,9 +128,11 @@ class Consumer(object):
except OCRError: except OCRError:
self._ignore.append(doc) self._ignore.append(doc)
Log.error("OCR FAILURE: {}".format(doc), Log.COMPONENT_CONSUMER) Log.error("OCR FAILURE: {}".format(doc), Log.COMPONENT_CONSUMER)
self._cleanup_tempdir(tempdir)
continue continue
finally: else:
self._cleanup(tempdir, doc) self._cleanup_tempdir(tempdir)
self._cleanup_doc(doc)
def _get_greyscale(self, tempdir, doc): def _get_greyscale(self, tempdir, doc):
@ -146,8 +148,12 @@ class Consumer(object):
"-type", "grayscale", doc, png "-type", "grayscale", doc, png
)).wait() )).wait()
pngs = [os.path.join(tempdir, f) for f in os.listdir(tempdir) if f.startswith("convert")] pngs = []
return sorted(filter(lambda f: os.path.isfile(f), pngs)) for f in os.listdir(tempdir):
if f.startswith("convert"):
pngs.append(os.path.join(tempdir, f))
return sorted(filter(lambda __: os.path.isfile(__), pngs))
@staticmethod @staticmethod
def _guess_language(text): def _guess_language(text):
@ -308,12 +314,13 @@ class Consumer(object):
Log.debug("Encrypting", Log.COMPONENT_CONSUMER) Log.debug("Encrypting", Log.COMPONENT_CONSUMER)
encrypted.write(GnuPG.encrypted(unencrypted)) encrypted.write(GnuPG.encrypted(unencrypted))
def _cleanup(self, tempdir, doc): @staticmethod
# Remove temporary directory recursively def _cleanup_tempdir(d):
Log.debug("Deleting directory {}".format(tempdir), Log.COMPONENT_CONSUMER) Log.debug("Deleting directory {}".format(d), Log.COMPONENT_CONSUMER)
shutil.rmtree(tempdir) shutil.rmtree(d)
# Remove doc @staticmethod
def _cleanup_doc(doc):
Log.debug("Deleting document {}".format(doc), Log.COMPONENT_CONSUMER) Log.debug("Deleting document {}".format(doc), Log.COMPONENT_CONSUMER)
os.unlink(doc) os.unlink(doc)