python filters: create common main program inside rclexecm.py to help with testing
This commit is contained in:
parent
d99865dbda
commit
9e994c4f62
@ -37,7 +37,6 @@ class AudioTagExtractor:
|
||||
def __init__(self, em):
|
||||
self.em = em
|
||||
self.currentindex = 0
|
||||
self.em.setmimetype("text/html")
|
||||
|
||||
def extractone(self, params):
|
||||
#self.em.rclog("extractone %s %s" % (params["filename:"], params["mimetype:"]))
|
||||
@ -76,6 +75,7 @@ class AudioTagExtractor:
|
||||
title = self.em.htmlescape(tags["title"][0].encode("utf-8"))
|
||||
except:
|
||||
pass
|
||||
self.em.setmimetype("text/html")
|
||||
alldata = self.em.htmlescape(tags.pprint().encode("utf-8"))
|
||||
alldata = alldata.replace("\n", "<br>")
|
||||
docdata = htmltemplate % (album, artist, title, alldata)
|
||||
@ -98,5 +98,6 @@ class AudioTagExtractor:
|
||||
self.currentindex += 1
|
||||
return ret
|
||||
|
||||
e = rclexecm.RclExecM()
|
||||
e.mainloop(AudioTagExtractor(e))
|
||||
proto = rclexecm.RclExecM()
|
||||
extract = AudioTagExtractor(proto)
|
||||
rclexecm.main(proto, extract)
|
||||
|
||||
@ -112,6 +112,7 @@ class rclCHM:
|
||||
res, doc = self.chm.RetrieveObject(ui)
|
||||
#self.em.rclog("extract: RetrieveObject: %d [%s]" % (res, doc))
|
||||
if res > 0:
|
||||
self.em.setmimetype("text/html")
|
||||
return (True, doc, path, iseof)
|
||||
return (False, "", path, iseof)
|
||||
|
||||
@ -146,5 +147,6 @@ class rclCHM:
|
||||
self.currentindex += 1
|
||||
return ret
|
||||
|
||||
e = rclexecm.RclExecM()
|
||||
e.mainloop(rclCHM(e))
|
||||
proto = rclexecm.RclExecM()
|
||||
extract = rclCHM(proto)
|
||||
rclexecm.main(proto, extract)
|
||||
|
||||
@ -28,6 +28,9 @@ class RclExecM:
|
||||
# Our worker sometimes knows the mime types of the data it sends
|
||||
def setmimetype(self, mt):
|
||||
self.mimetype = mt
|
||||
|
||||
# Read single parameter from process input: line with param name and size
|
||||
# followed by data.
|
||||
def readparam(self):
|
||||
s = sys.stdin.readline()
|
||||
if s == '':
|
||||
@ -95,6 +98,7 @@ class RclExecM:
|
||||
|
||||
# If we have an ipath, that's what we look for, else ask for next entry
|
||||
ipath = ""
|
||||
self.mimetype = ""
|
||||
if params.has_key("ipath:") and len(params["ipath:"]):
|
||||
ok, data, ipath, eof = processor.getipath(params)
|
||||
else:
|
||||
@ -123,3 +127,42 @@ class RclExecM:
|
||||
# Got message, act on it
|
||||
self.processmessage(processor, params)
|
||||
|
||||
|
||||
# Common main routine for all python execm filters: either run the
|
||||
# normal protocol engine or a local loop to test without recollindex
|
||||
def main(proto, extract):
|
||||
if len(sys.argv) == 1:
|
||||
proto.mainloop(extract)
|
||||
else:
|
||||
# Got a file name parameter: TESTING without an execm parent
|
||||
# Loop on all entries or get specific ipath
|
||||
if not extract.openfile({'filename:':sys.argv[1]}):
|
||||
print "Open error"
|
||||
sys.exit(1)
|
||||
ipath = ""
|
||||
if len(sys.argv) == 3:
|
||||
ipath = sys.argv[2]
|
||||
|
||||
if ipath != "":
|
||||
ok, data, ipath, eof = extract.getipath({'ipath:':ipath})
|
||||
if ok:
|
||||
print "== Found entry for ipath %s (mimetype [%s]):" % \
|
||||
(ipath, proto.mimetype)
|
||||
print data
|
||||
print
|
||||
else:
|
||||
print "Got error, eof %d"%eof
|
||||
sys.exit(0)
|
||||
|
||||
ecnt = 0
|
||||
while 1:
|
||||
ok, data, ipath, eof = extract.getnext("")
|
||||
if ok:
|
||||
ecnt = ecnt + 1
|
||||
print "== Entry %d ipath %s (mimetype [%s]:" % \
|
||||
(ecnt, ipath, proto.mimetype)
|
||||
# print data
|
||||
print
|
||||
else:
|
||||
print "Not ok, eof %d" % eof
|
||||
break
|
||||
|
||||
@ -37,7 +37,6 @@ class IcalExtractor:
|
||||
self.file = ""
|
||||
self.contents = []
|
||||
self.em = em
|
||||
self.em.setmimetype("text/plain")
|
||||
|
||||
def extractone(self, index):
|
||||
if index >= len(self.contents):
|
||||
@ -48,6 +47,7 @@ class IcalExtractor:
|
||||
iseof = rclexecm.RclExecM.noteof
|
||||
if self.currentindex >= len(self.contents) -1:
|
||||
iseof = rclexecm.RclExecM.eofnext
|
||||
self.em.setmimetype("text/plain")
|
||||
return (True, docdata, str(index), iseof)
|
||||
|
||||
###### File type handler api, used by rclexecm ---------->
|
||||
@ -152,29 +152,6 @@ class ICalSimpleSplitter:
|
||||
return lo
|
||||
|
||||
|
||||
##### Main program: either talk to the parent or execute test loop
|
||||
|
||||
e = rclexecm.RclExecM()
|
||||
ical = IcalExtractor(e)
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
e.mainloop(ical)
|
||||
else:
|
||||
# Got a file name parameter: testing without an execm parent
|
||||
# Loop on all entries
|
||||
if not ical.openfile({'filename:':sys.argv[1]}):
|
||||
print "Open error"
|
||||
sys.exit(1)
|
||||
|
||||
ecnt = 0
|
||||
while 1:
|
||||
ok, data, ipath, eof = ical.getnext("")
|
||||
if ok:
|
||||
ecnt = ecnt + 1
|
||||
print "=========== ENTRY %d =================" % ecnt
|
||||
print data
|
||||
print
|
||||
else:
|
||||
print "Got error, eof %d"%eof
|
||||
break
|
||||
|
||||
proto = rclexecm.RclExecM()
|
||||
extract = IcalExtractor(proto)
|
||||
rclexecm.main(proto, extract)
|
||||
|
||||
@ -29,7 +29,6 @@ class InfoExtractor:
|
||||
self.file = ""
|
||||
self.contents = []
|
||||
self.em = em
|
||||
self.em.setmimetype("text/html")
|
||||
|
||||
def extractone(self, index):
|
||||
if index >= len(self.contents):
|
||||
@ -44,6 +43,7 @@ class InfoExtractor:
|
||||
iseof = rclexecm.RclExecM.noteof
|
||||
if self.currentindex >= len(self.contents) -1:
|
||||
iseof = rclexecm.RclExecM.eofnext
|
||||
self.em.setmimetype("text/html")
|
||||
return (True, docdata, str(index), iseof)
|
||||
|
||||
###### File type handler api, used by rclexecm ---------->
|
||||
@ -195,41 +195,6 @@ class InfoSimpleSplitter:
|
||||
|
||||
|
||||
##### Main program: either talk to the parent or execute test loop
|
||||
|
||||
e = rclexecm.RclExecM()
|
||||
info = InfoExtractor(e)
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
e.mainloop(info)
|
||||
else:
|
||||
# Got a file name parameter: TESTING without an execm parent
|
||||
# Loop on all entries or get specific ipath
|
||||
if not info.openfile({'filename:':sys.argv[1]}):
|
||||
print "Open error"
|
||||
sys.exit(1)
|
||||
ipath = ""
|
||||
if len(sys.argv) == 3:
|
||||
ipath = sys.argv[2]
|
||||
|
||||
if ipath != "":
|
||||
ok, data, ipath, eof = info.getipath({'ipath:':ipath})
|
||||
if ok:
|
||||
print "=========== ENTRY for IPATH %s =============" % (ipath)
|
||||
print data
|
||||
print
|
||||
else:
|
||||
print "Got error, eof %d"%eof
|
||||
sys.exit(0)
|
||||
|
||||
ecnt = 0
|
||||
while 1:
|
||||
ok, data, ipath, eof = info.getnext("")
|
||||
if ok:
|
||||
ecnt = ecnt + 1
|
||||
print "=========== ENTRY %d IPATH %s =============" % (ecnt,ipath)
|
||||
# print data
|
||||
print
|
||||
else:
|
||||
print "Got error, eof %d"%eof
|
||||
break
|
||||
|
||||
proto = rclexecm.RclExecM()
|
||||
extract = InfoExtractor(proto)
|
||||
rclexecm.main(proto, extract)
|
||||
|
||||
@ -48,5 +48,7 @@ class ZipExtractor:
|
||||
self.currentindex += 1
|
||||
return ret
|
||||
|
||||
e = rclexecm.RclExecM()
|
||||
e.mainloop(ZipExtractor(e))
|
||||
# Main program: create protocol handler and extractor and run them
|
||||
proto = rclexecm.RclExecM()
|
||||
extract = ZipExtractor(proto)
|
||||
rclexecm.main(proto, extract)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user