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):
|
def __init__(self, em):
|
||||||
self.em = em
|
self.em = em
|
||||||
self.currentindex = 0
|
self.currentindex = 0
|
||||||
self.em.setmimetype("text/html")
|
|
||||||
|
|
||||||
def extractone(self, params):
|
def extractone(self, params):
|
||||||
#self.em.rclog("extractone %s %s" % (params["filename:"], params["mimetype:"]))
|
#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"))
|
title = self.em.htmlescape(tags["title"][0].encode("utf-8"))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
self.em.setmimetype("text/html")
|
||||||
alldata = self.em.htmlescape(tags.pprint().encode("utf-8"))
|
alldata = self.em.htmlescape(tags.pprint().encode("utf-8"))
|
||||||
alldata = alldata.replace("\n", "<br>")
|
alldata = alldata.replace("\n", "<br>")
|
||||||
docdata = htmltemplate % (album, artist, title, alldata)
|
docdata = htmltemplate % (album, artist, title, alldata)
|
||||||
@ -98,5 +98,6 @@ class AudioTagExtractor:
|
|||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
e = rclexecm.RclExecM()
|
proto = rclexecm.RclExecM()
|
||||||
e.mainloop(AudioTagExtractor(e))
|
extract = AudioTagExtractor(proto)
|
||||||
|
rclexecm.main(proto, extract)
|
||||||
|
|||||||
@ -112,6 +112,7 @@ class rclCHM:
|
|||||||
res, doc = self.chm.RetrieveObject(ui)
|
res, doc = self.chm.RetrieveObject(ui)
|
||||||
#self.em.rclog("extract: RetrieveObject: %d [%s]" % (res, doc))
|
#self.em.rclog("extract: RetrieveObject: %d [%s]" % (res, doc))
|
||||||
if res > 0:
|
if res > 0:
|
||||||
|
self.em.setmimetype("text/html")
|
||||||
return (True, doc, path, iseof)
|
return (True, doc, path, iseof)
|
||||||
return (False, "", path, iseof)
|
return (False, "", path, iseof)
|
||||||
|
|
||||||
@ -146,5 +147,6 @@ class rclCHM:
|
|||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
e = rclexecm.RclExecM()
|
proto = rclexecm.RclExecM()
|
||||||
e.mainloop(rclCHM(e))
|
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
|
# Our worker sometimes knows the mime types of the data it sends
|
||||||
def setmimetype(self, mt):
|
def setmimetype(self, mt):
|
||||||
self.mimetype = mt
|
self.mimetype = mt
|
||||||
|
|
||||||
|
# Read single parameter from process input: line with param name and size
|
||||||
|
# followed by data.
|
||||||
def readparam(self):
|
def readparam(self):
|
||||||
s = sys.stdin.readline()
|
s = sys.stdin.readline()
|
||||||
if s == '':
|
if s == '':
|
||||||
@ -95,6 +98,7 @@ class RclExecM:
|
|||||||
|
|
||||||
# If we have an ipath, that's what we look for, else ask for next entry
|
# If we have an ipath, that's what we look for, else ask for next entry
|
||||||
ipath = ""
|
ipath = ""
|
||||||
|
self.mimetype = ""
|
||||||
if params.has_key("ipath:") and len(params["ipath:"]):
|
if params.has_key("ipath:") and len(params["ipath:"]):
|
||||||
ok, data, ipath, eof = processor.getipath(params)
|
ok, data, ipath, eof = processor.getipath(params)
|
||||||
else:
|
else:
|
||||||
@ -123,3 +127,42 @@ class RclExecM:
|
|||||||
# Got message, act on it
|
# Got message, act on it
|
||||||
self.processmessage(processor, params)
|
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.file = ""
|
||||||
self.contents = []
|
self.contents = []
|
||||||
self.em = em
|
self.em = em
|
||||||
self.em.setmimetype("text/plain")
|
|
||||||
|
|
||||||
def extractone(self, index):
|
def extractone(self, index):
|
||||||
if index >= len(self.contents):
|
if index >= len(self.contents):
|
||||||
@ -48,6 +47,7 @@ class IcalExtractor:
|
|||||||
iseof = rclexecm.RclExecM.noteof
|
iseof = rclexecm.RclExecM.noteof
|
||||||
if self.currentindex >= len(self.contents) -1:
|
if self.currentindex >= len(self.contents) -1:
|
||||||
iseof = rclexecm.RclExecM.eofnext
|
iseof = rclexecm.RclExecM.eofnext
|
||||||
|
self.em.setmimetype("text/plain")
|
||||||
return (True, docdata, str(index), iseof)
|
return (True, docdata, str(index), iseof)
|
||||||
|
|
||||||
###### File type handler api, used by rclexecm ---------->
|
###### File type handler api, used by rclexecm ---------->
|
||||||
@ -152,29 +152,6 @@ class ICalSimpleSplitter:
|
|||||||
return lo
|
return lo
|
||||||
|
|
||||||
|
|
||||||
##### Main program: either talk to the parent or execute test loop
|
proto = rclexecm.RclExecM()
|
||||||
|
extract = IcalExtractor(proto)
|
||||||
e = rclexecm.RclExecM()
|
rclexecm.main(proto, extract)
|
||||||
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
|
|
||||||
|
|
||||||
|
|||||||
@ -29,7 +29,6 @@ class InfoExtractor:
|
|||||||
self.file = ""
|
self.file = ""
|
||||||
self.contents = []
|
self.contents = []
|
||||||
self.em = em
|
self.em = em
|
||||||
self.em.setmimetype("text/html")
|
|
||||||
|
|
||||||
def extractone(self, index):
|
def extractone(self, index):
|
||||||
if index >= len(self.contents):
|
if index >= len(self.contents):
|
||||||
@ -44,6 +43,7 @@ class InfoExtractor:
|
|||||||
iseof = rclexecm.RclExecM.noteof
|
iseof = rclexecm.RclExecM.noteof
|
||||||
if self.currentindex >= len(self.contents) -1:
|
if self.currentindex >= len(self.contents) -1:
|
||||||
iseof = rclexecm.RclExecM.eofnext
|
iseof = rclexecm.RclExecM.eofnext
|
||||||
|
self.em.setmimetype("text/html")
|
||||||
return (True, docdata, str(index), iseof)
|
return (True, docdata, str(index), iseof)
|
||||||
|
|
||||||
###### File type handler api, used by rclexecm ---------->
|
###### File type handler api, used by rclexecm ---------->
|
||||||
@ -195,41 +195,6 @@ class InfoSimpleSplitter:
|
|||||||
|
|
||||||
|
|
||||||
##### Main program: either talk to the parent or execute test loop
|
##### Main program: either talk to the parent or execute test loop
|
||||||
|
proto = rclexecm.RclExecM()
|
||||||
e = rclexecm.RclExecM()
|
extract = InfoExtractor(proto)
|
||||||
info = InfoExtractor(e)
|
rclexecm.main(proto, extract)
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
|
|||||||
@ -48,5 +48,7 @@ class ZipExtractor:
|
|||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
e = rclexecm.RclExecM()
|
# Main program: create protocol handler and extractor and run them
|
||||||
e.mainloop(ZipExtractor(e))
|
proto = rclexecm.RclExecM()
|
||||||
|
extract = ZipExtractor(proto)
|
||||||
|
rclexecm.main(proto, extract)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user