Parent: [8324f0] (diff)

Download this file

rcluncomp.py    53 lines (43 with data), 1.6 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python2
from __future__ import print_function
import rclexecm
import sys
import os
import shutil
import platform
import subprocess
import glob
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 = 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=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
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)
sys.exit(0)