Arrange so we can now open the parent of a document (e.g. chm file instead of temp copy of html page inside chm), even when the parent is itself embedded in an archive

This commit is contained in:
Jean-Francois Dockes
2012-10-12 16:54:52 +02:00
parent 382ae1f718
commit 5add2e2384
13 changed files with 222 additions and 59 deletions
+11 -4
View File
@@ -190,7 +190,6 @@ class rclCHM:
def __init__(self, em):
self.contents = []
self.chm = chm.CHMFile()
self.currentindex = 0
self.em = em
if rclchm_catenate:
self.em.setmimetype("text/plain")
@@ -240,7 +239,7 @@ class rclCHM:
"""Open the chm file and build the contents list by extracting and
parsing the Topics object"""
self.currentindex = 0
self.currentindex = -1
self.contents = []
filename = params["filename:"]
@@ -248,8 +247,6 @@ class rclCHM:
self.em.rclog("LoadCHM failed")
return False
self.sfn = os.path.basename(filename)
#self.em.rclog("home [%s] topics [%s] title [%s]" %
# (self.chm.home, self.chm.topics, self.chm.title))
@@ -293,6 +290,16 @@ class rclCHM:
else:
return (False, "", "", rclexecm.RclExecM.eofnow)
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.contents) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.contents):
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
+12 -1
View File
@@ -48,7 +48,7 @@ class rclEPUB:
def openfile(self, params):
"""Open the EPUB file, create a contents array"""
self.currentindex = 0
self.currentindex = -1
self.contents = []
try:
self.book = epub.open(params["filename:"])
@@ -65,6 +65,17 @@ class rclEPUB:
return self.extractone(params["ipath:"])
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.contents) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.contents):
return (False, "", "", rclexecm.RclExecM.eofnow)
else:
+12 -1
View File
@@ -60,7 +60,7 @@ class IcalExtractor:
self.em.rclog("Openfile: open: %s" % str(e))
return False
self.currentindex = 0
self.currentindex = -1
if usemodule == 'internal':
self.contents = ICalSimpleSplitter().splitcalendar(calstr)
@@ -96,6 +96,17 @@ class IcalExtractor:
return self.extractone(index)
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.contents) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.contents):
self.em.rclog("getnext: EOF hit")
return (False, "", "", rclexecm.RclExecM.eofnow)
+12 -1
View File
@@ -73,7 +73,7 @@ class InfoExtractor:
sys.exit(1);
self.currentindex = 0
self.currentindex = -1
self.contents = InfoSimpleSplitter().splitinfo(self.file, infostream)
@@ -90,6 +90,17 @@ class InfoExtractor:
# Extract next in list
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.contents) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.contents):
self.em.rclog("getnext: EOF hit")
return (False, "", "", rclexecm.RclExecM.eofnow)
+12 -1
View File
@@ -73,7 +73,7 @@ class RarExtractor:
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
self.currentindex = 0
self.currentindex = -1
try:
self.rar = RarFile(params["filename:"])
return True
@@ -93,6 +93,17 @@ class RarExtractor:
return (ok, data, ipath, eof)
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.rar.namelist()) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.rar.namelist()):
#self.em.rclog("getnext: EOF hit")
return (False, "", "", rclexecm.RclExecM.eofnow)
+12 -1
View File
@@ -43,7 +43,7 @@ class TarExtractor:
return (ok, docdata, ipath, iseof)
def openfile(self, params):
self.currentindex = 0
self.currentindex = -1
try:
self.tar = open(name=params["filename:"],mode='r')
self.namen = [ y.name for y in filter(lambda z:z.isfile(),self.tar.getmembers())]
@@ -63,6 +63,17 @@ class TarExtractor:
return (ok, data, ipath, eof)
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.namen) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.namen):
self.namen=[]
return (False, "", "", rclexecm.RclExecM.eofnow)
+6 -1
View File
@@ -22,7 +22,7 @@ class WarExtractor:
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
self.currentindex = 0
self.currentindex = -1
try:
self.tar = tarfile.open(params["filename:"])
return True
@@ -40,6 +40,11 @@ class WarExtractor:
return self.extractone(tarinfo)
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
return (True, "", "", rclexecm.RclExecM.noteof)
tarinfo = self.tar.next()
if tarinfo is None:
#self.em.rclog("getnext: EOF hit")
+11 -1
View File
@@ -67,7 +67,7 @@ class ZipExtractor:
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
self.currentindex = 0
self.currentindex = -1
try:
self.zip = ZipFile(params["filename:"])
return True
@@ -87,6 +87,16 @@ class ZipExtractor:
return (ok, data, ipath, eof)
def getnext(self, params):
if self.currentindex == -1:
# Return "self" doc
self.currentindex = 0
self.em.setmimetype('text/plain')
if len(self.zip.namelist()) == 0:
eof = rclexecm.RclExecM.eofnext
else:
eof = rclexecm.RclExecM.noteof
return (True, "", "", eof)
if self.currentindex >= len(self.zip.namelist()):
#self.em.rclog("getnext: EOF hit")
return (False, "", "", rclexecm.RclExecM.eofnow)