Allow execm input handlers to set arbitrary data fields
This commit is contained in:
parent
067226a8b2
commit
72e9b896bf
3 changed files with 47 additions and 14 deletions
|
@ -66,6 +66,8 @@ class RclExecM:
|
||||||
self.myname = "???"
|
self.myname = "???"
|
||||||
self.mimetype = b""
|
self.mimetype = b""
|
||||||
|
|
||||||
|
self.fields = {}
|
||||||
|
|
||||||
if os.environ.get("RECOLL_FILTER_MAXMEMBERKB"):
|
if os.environ.get("RECOLL_FILTER_MAXMEMBERKB"):
|
||||||
self.maxmembersize = \
|
self.maxmembersize = \
|
||||||
int(os.environ.get("RECOLL_FILTER_MAXMEMBERKB"))
|
int(os.environ.get("RECOLL_FILTER_MAXMEMBERKB"))
|
||||||
|
@ -125,6 +127,9 @@ class RclExecM:
|
||||||
def setmimetype(self, mt):
|
def setmimetype(self, mt):
|
||||||
self.mimetype = makebytes(mt)
|
self.mimetype = makebytes(mt)
|
||||||
|
|
||||||
|
def setfield(self, nm, value):
|
||||||
|
self.fields[nm] = value
|
||||||
|
|
||||||
# Read single parameter from process input: line with param name and size
|
# Read single parameter from process input: line with param name and size
|
||||||
# followed by data. The param name is returned as str/unicode, the data
|
# followed by data. The param name is returned as str/unicode, the data
|
||||||
# as bytes
|
# as bytes
|
||||||
|
@ -160,35 +165,44 @@ class RclExecM:
|
||||||
return (paramname, paramdata)
|
return (paramname, paramdata)
|
||||||
|
|
||||||
if PY3:
|
if PY3:
|
||||||
def senditem(self, nm, len, data):
|
def senditem(self, nm, data):
|
||||||
sys.stdout.buffer.write(makebytes("%s: %d\n" % (nm, len)))
|
data = makebytes(data)
|
||||||
self.breakwrite(sys.stdout.buffer, makebytes(data))
|
l = len(data)
|
||||||
|
sys.stdout.buffer.write(makebytes("%s: %d\n" % (nm, l)))
|
||||||
|
self.breakwrite(sys.stdout.buffer, data)
|
||||||
else:
|
else:
|
||||||
def senditem(self, nm, len, data):
|
def senditem(self, nm, data):
|
||||||
sys.stdout.write(makebytes("%s: %d\n" % (nm, len)))
|
data = makebytes(data)
|
||||||
self.breakwrite(sys.stdout, makebytes(data))
|
l = len(data)
|
||||||
|
sys.stdout.write(makebytes("%s: %d\n" % (nm, l)))
|
||||||
|
self.breakwrite(sys.stdout, data)
|
||||||
|
|
||||||
# Send answer: document, ipath, possible eof.
|
# Send answer: document, ipath, possible eof.
|
||||||
def answer(self, docdata, ipath, iseof = noteof, iserror = noerror):
|
def answer(self, docdata, ipath, iseof = noteof, iserror = noerror):
|
||||||
|
|
||||||
if iserror != RclExecM.fileerror and iseof != RclExecM.eofnow:
|
if iserror != RclExecM.fileerror and iseof != RclExecM.eofnow:
|
||||||
self.senditem("Document", len(docdata), docdata)
|
self.senditem("Document", docdata)
|
||||||
|
|
||||||
if len(ipath):
|
if len(ipath):
|
||||||
self.senditem("Ipath", len(ipath), ipath)
|
self.senditem("Ipath", ipath)
|
||||||
|
|
||||||
if len(self.mimetype):
|
if len(self.mimetype):
|
||||||
self.senditem("Mimetype", len(self.mimetype), self.mimetype)
|
self.senditem("Mimetype", self.mimetype)
|
||||||
|
|
||||||
|
for nm,value in self.fields.iteritems():
|
||||||
|
#self.rclog("Senditem: [%s] -> [%s]" % (nm, value))
|
||||||
|
self.senditem("%s:"%nm, value)
|
||||||
|
self.fields = {}
|
||||||
|
|
||||||
# If we're at the end of the contents, say so
|
# If we're at the end of the contents, say so
|
||||||
if iseof == RclExecM.eofnow:
|
if iseof == RclExecM.eofnow:
|
||||||
self.senditem("Eofnow", 0, b'')
|
self.senditem("Eofnow", b'')
|
||||||
elif iseof == RclExecM.eofnext:
|
elif iseof == RclExecM.eofnext:
|
||||||
self.senditem("Eofnext", 0, b'')
|
self.senditem("Eofnext", b'')
|
||||||
if iserror == RclExecM.subdocerror:
|
if iserror == RclExecM.subdocerror:
|
||||||
self.senditem("Subdocerror", 0, b'')
|
self.senditem("Subdocerror", b'')
|
||||||
elif iserror == RclExecM.fileerror:
|
elif iserror == RclExecM.fileerror:
|
||||||
self.senditem("Fileerror", 0, b'')
|
self.senditem("Fileerror", b'')
|
||||||
|
|
||||||
# End of message
|
# End of message
|
||||||
print()
|
print()
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import posixpath
|
||||||
import fnmatch
|
import fnmatch
|
||||||
import rclexecm
|
import rclexecm
|
||||||
from zipfile import ZipFile
|
from zipfile import ZipFile
|
||||||
|
@ -89,6 +90,16 @@ class ZipExtractor:
|
||||||
#raise BadZipfile()
|
#raise BadZipfile()
|
||||||
else:
|
else:
|
||||||
docdata = self.zip.read(ipath)
|
docdata = self.zip.read(ipath)
|
||||||
|
try:
|
||||||
|
# We are assuming here that the zip uses forward slash
|
||||||
|
# separators, which is not necessarily the case. At
|
||||||
|
# worse, we'll get a wrong or no file name, which is
|
||||||
|
# no big deal (the ipath is the important data
|
||||||
|
# element).
|
||||||
|
filename = posixpath.basename(ipath)
|
||||||
|
self.em.setfield("filename", filename)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
ok = True
|
ok = True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.em.rclog("extractone: failed: [%s]" % err)
|
self.em.rclog("extractone: failed: [%s]" % err)
|
||||||
|
|
|
@ -169,6 +169,8 @@ bool MimeHandlerExecMultiple::next_document()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_metaData.clear();
|
||||||
|
|
||||||
// Send request to child process. This maybe the first/only
|
// Send request to child process. This maybe the first/only
|
||||||
// request for a given file, or a continuation request. We send an
|
// request for a given file, or a continuation request. We send an
|
||||||
// empty file name in the latter case.
|
// empty file name in the latter case.
|
||||||
|
@ -260,8 +262,14 @@ bool MimeHandlerExecMultiple::next_document()
|
||||||
} else if (!stringlowercmp("mimetype:", name)) {
|
} else if (!stringlowercmp("mimetype:", name)) {
|
||||||
mtype = data;
|
mtype = data;
|
||||||
LOGDEB(("MHExecMultiple: got mimetype [%s]\n", data.c_str()));
|
LOGDEB(("MHExecMultiple: got mimetype [%s]\n", data.c_str()));
|
||||||
|
} else {
|
||||||
|
string nm = stringtolower((const string&)name);
|
||||||
|
trimstring(nm, ":");
|
||||||
|
LOGDEB(("MHExecMultiple: got [%s] -> [%s]\n", nm.c_str(),
|
||||||
|
data.c_str()));
|
||||||
|
m_metaData[nm] += data;
|
||||||
}
|
}
|
||||||
if (loop == 10) {
|
if (loop == 20) {
|
||||||
// ??
|
// ??
|
||||||
LOGERR(("MHExecMultiple: filter sent too many parameters\n"));
|
LOGERR(("MHExecMultiple: filter sent too many parameters\n"));
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue