index: support webarchive (.war) and mimehtml (.mhtml) formats

This commit is contained in:
Jean-Francois Dockes
2011-03-26 17:29:04 +01:00
parent 22788b8900
commit d0cb158d26
3 changed files with 61 additions and 1 deletions
+54
View File
@@ -0,0 +1,54 @@
#!/usr/bin/env python
# WAR web archive filter for recoll. War file are gzipped tar files
import rclexecm
import tarfile
class WarExtractor:
def __init__(self, em):
self.em = em
def extractone(self, tarinfo):
docdata = ""
try:
member = self.tar.extractfile(tarinfo)
docdata = member.read()
ok = True
except Exception, err:
self.em.rclog("extractone: failed: [%s]" % err)
ok = False
return (ok, docdata, tarinfo.name, rclexecm.RclExecM.noteof)
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
self.currentindex = 0
try:
self.tar = tarfile.open(params["filename:"])
return True
except Exception, err:
self.em.rclog(str(err))
return False
def getipath(self, params):
ipath = params["ipath:"]
try:
tarinfo = self.tar.getmember(ipath)
except Exception, err:
self.em.rclog(str(err))
return (False, "", ipath, rclexecm.RclExecM.noteof)
return self.extractone(tarinfo)
def getnext(self, params):
tarinfo = self.tar.next()
if tarinfo is None:
#self.em.rclog("getnext: EOF hit")
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
ret = self.extractone(tarinfo)
return ret
# Main program: create protocol handler and extractor and run them
proto = rclexecm.RclExecM()
extract = WarExtractor(proto)
rclexecm.main(proto, extract)