Get uncompression to work and fix a few other issues

This commit is contained in:
Jean-Francois Dockes
2015-10-13 16:48:16 +02:00
parent a02a611694
commit 8324f09d19
8 changed files with 65 additions and 28 deletions
+10 -4
View File
@@ -70,6 +70,7 @@ class PDFExtractor:
self.pdftk = ""
self.em = em
self.attextractdone = False
self.attachlist = []
# Extract all attachments if any into temporary directory
def extractAttach(self):
@@ -79,7 +80,8 @@ class PDFExtractor:
global tmpdir
if not tmpdir or not self.pdftk:
return False
# no big deal
return True
try:
vacuumdir(tmpdir)
@@ -89,7 +91,8 @@ class PDFExtractor:
return True
except Exception, e:
self.em.rclog("extractAttach: failed: %s" % e)
return False
# Return true anyway, pdf attachments are no big deal
return True
def extractone(self, ipath):
#self.em.rclog("extractone: [%s]" % ipath)
@@ -186,6 +189,8 @@ class PDFExtractor:
if not self.pdftotext:
self.pdftotext = rclexecm.which("pdftotext")
if not self.pdftotext:
self.pdftotext = rclexecm.which("poppler/pdftotext")
if not self.pdftotext:
print("RECFILTERROR HELPERNOTFOUND pdftotext")
sys.exit(1);
@@ -209,7 +214,8 @@ class PDFExtractor:
# eofnext error instead of waiting for actual eof,
# which avoids a bug in recollindex up to 1.20
self.extractAttach()
else:
self.attextractdone = True
return True
def getipath(self, params):
@@ -218,8 +224,8 @@ class PDFExtractor:
return (ok, data, ipath, eof)
def getnext(self, params):
# self.em.rclog("getnext: current %d" % self.currentindex)
if self.currentindex == -1:
#self.em.rclog("getnext: current -1")
self.currentindex = 0
return self._selfdoc()
else:
+24 -10
View File
@@ -9,30 +9,44 @@ import platform
import subprocess
import glob
sysplat = platform.system()
ftrace = sys.stderr
#ftrace = open("C:/Users/Bill/log-uncomp.txt", "w")
sysplat = platform.system()
if sysplat != "Windows":
print("rcluncomp.py: only for Windows", file = sys.stderr)
print("rcluncomp.py: only for Windows", file = ftrace)
sys.exit(1)
try:
import msvcrt
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
except Exception as err:
print("setmode binary failed: %s" % str(err), file = ftrace)
sevenz = rclexecm.which("7z")
if not sevenz:
print("rcluncomp.py: can't find 7z exe. Maybe set recollhelperpath " \
"in recoll.conf ?", file=sys.stderr)
sys.exit(1)
#print("rcluncomp.py: 7z is %s" % sevenz, file = sys.stderr)
"in recoll.conf ?", file=ftrace)
sys.exit(2)
# Params: uncompression program, input file name, temp directory.
# We ignore the uncomp program, and always use 7z on Windows
infile = sys.argv[2]
outdir = sys.argv[3]
# print("rcluncomp.py infile [%s], outdir [%s]" % (infile, outdir), file = ftrace)
# There is apparently no way to suppress 7z output. Hopefully the
# possible deadlock described by the subprocess module doc can't occur
# here because there is little data printed. AFAIK nothing goes to stderr anyway
subprocess.check_output([sevenz, "e", "-bd", "-y", "-o" + outdir, infile],
stderr = subprocess.PIPE)
try:
cmd = [sevenz, "e", "-bd", "-y", "-o" + outdir, infile]
subprocess.check_output(cmd, stderr = subprocess.PIPE)
outputname = glob.glob(os.path.join(outdir, "*"))
# There should be only one file in there..
print(outputname[0])
except Exception as err:
print("%s" % (str(err),), file = ftrace)
sys.exit(4)
outputname = glob.glob(os.path.join(outdir, "*"))
# There should be only one file in there..
print(outputname[0])
sys.exit(0)