Initial Commit
commit
f5e1e11d50
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys
|
||||
import os
|
||||
import fasteners
|
||||
import time
|
||||
import subprocess
|
||||
|
||||
OCRBASE="/ocr"
|
||||
|
||||
|
||||
lock = fasteners.InterProcessLock("/var/lock/ocr-watcher.lock")
|
||||
|
||||
if lock.acquire(timeout=2):
|
||||
while (True):
|
||||
for e in os.scandir(OCRBASE):
|
||||
SRCFILE="{}/{}".format(OCRBASE, e.name)
|
||||
FAILFILE="{}/failed/{}".format(OCRBASE, e.name)
|
||||
|
||||
if e.is_file() and e.name.endswith(".pdf"):
|
||||
SPOOLFILE="{}/spool/{}".format(OCRBASE, e.name)
|
||||
TEMPFILE="{}/spool/{}.tmp".format(OCRBASE, e.name)
|
||||
ARCHIVEFILE="{}/archive/{}".format(OCRBASE, e.name)
|
||||
DSTFILE="{}/ocr/{}".format(OCRBASE, e.name)
|
||||
LOGFILE="{}/log/{}.out".format(OCRBASE, e.name)
|
||||
ERRFILE="{}/log/{}.err".format(OCRBASE, e.name)
|
||||
|
||||
# os.rename(SRCFILE, SPOOLFILE)
|
||||
|
||||
with open(LOGFILE,"w") as logfile:
|
||||
with open(ERRFILE,"w") as errfile:
|
||||
|
||||
if subprocess.run(["/usr/bin/ocrmypdf","-l","deu","--rotate-pages","--deskew","--jobs","4", SRCFILE, TEMPFILE], stderr=errfile, stdout=logfile).returncode != 0:
|
||||
if os.path.isfile(TEMPFILE):
|
||||
os.unlink(TEMPFILE)
|
||||
os.rename(SRCFILE, FAILFILE)
|
||||
else:
|
||||
os.rename(SRCFILE, ARCHIVEFILE)
|
||||
os.rename(TEMPFILE, DSTFILE)
|
||||
elif not e.name.startswith(".") and not e.is_dir():
|
||||
os.rename(SRCFILE, FAILFILE)
|
||||
time.sleep(5)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue