Input handlers: more closing to help with windows temp files
This commit is contained in:
parent
a1daa8de55
commit
af664e7768
@ -35,6 +35,7 @@ if not hasrclconfig:
|
|||||||
class SevenZipExtractor:
|
class SevenZipExtractor:
|
||||||
def __init__(self, em):
|
def __init__(self, em):
|
||||||
self.currentindex = 0
|
self.currentindex = 0
|
||||||
|
self.fp = None
|
||||||
self.em = em
|
self.em = em
|
||||||
|
|
||||||
def extractone(self, ipath):
|
def extractone(self, ipath):
|
||||||
@ -51,6 +52,10 @@ class SevenZipExtractor:
|
|||||||
iseof = rclexecm.RclExecM.eofnext
|
iseof = rclexecm.RclExecM.eofnext
|
||||||
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
|
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
|
||||||
|
|
||||||
|
def closefile(self):
|
||||||
|
if self.fp:
|
||||||
|
self.fp.close()
|
||||||
|
|
||||||
###### File type handler api, used by rclexecm ---------->
|
###### File type handler api, used by rclexecm ---------->
|
||||||
def openfile(self, params):
|
def openfile(self, params):
|
||||||
filename = params["filename:"]
|
filename = params["filename:"]
|
||||||
@ -65,8 +70,8 @@ class SevenZipExtractor:
|
|||||||
self.skiplist = skipped.split(" ")
|
self.skiplist = skipped.split(" ")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fp = open(filename, 'rb')
|
self.fp = open(filename, 'rb')
|
||||||
self.sevenzip = Archive7z(fp)
|
self.sevenzip = Archive7z(self.fp)
|
||||||
return True
|
return True
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
self.em.rclog("openfile: failed: [%s]" % err)
|
self.em.rclog("openfile: failed: [%s]" % err)
|
||||||
@ -90,6 +95,7 @@ class SevenZipExtractor:
|
|||||||
self.currentindex = 0
|
self.currentindex = 0
|
||||||
self.em.setmimetype('text/plain')
|
self.em.setmimetype('text/plain')
|
||||||
if len(self.sevenzip.getnames()) == 0:
|
if len(self.sevenzip.getnames()) == 0:
|
||||||
|
self.closefile()
|
||||||
eof = rclexecm.RclExecM.eofnext
|
eof = rclexecm.RclExecM.eofnext
|
||||||
else:
|
else:
|
||||||
eof = rclexecm.RclExecM.noteof
|
eof = rclexecm.RclExecM.noteof
|
||||||
@ -97,6 +103,7 @@ class SevenZipExtractor:
|
|||||||
|
|
||||||
if self.currentindex >= len(self.sevenzip.getnames()):
|
if self.currentindex >= len(self.sevenzip.getnames()):
|
||||||
#self.em.rclog("getnext: EOF hit")
|
#self.em.rclog("getnext: EOF hit")
|
||||||
|
self.closefile()
|
||||||
return (False, "", "", rclexecm.RclExecM.eofnow)
|
return (False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
else:
|
else:
|
||||||
entryname = self.sevenzip.getnames()[self.currentindex]
|
entryname = self.sevenzip.getnames()[self.currentindex]
|
||||||
@ -112,9 +119,13 @@ class SevenZipExtractor:
|
|||||||
break
|
break
|
||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
if entryname is None:
|
if entryname is None:
|
||||||
|
self.closefile()
|
||||||
return (False, "", "", rclexecm.RclExecM.eofnow)
|
return (False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
|
|
||||||
ret= self.extractone(entryname)
|
ret = self.extractone(entryname)
|
||||||
|
if ret[3] == rclexecm.RclExecM.eofnext or \
|
||||||
|
ret[3] == rclexecm.RclExecM.eofnow:
|
||||||
|
self.closefile()
|
||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|||||||
@ -97,6 +97,9 @@ class RarExtractor:
|
|||||||
iseof = rclexecm.RclExecM.eofnext
|
iseof = rclexecm.RclExecM.eofnext
|
||||||
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
|
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
|
||||||
|
|
||||||
|
def closefile(self):
|
||||||
|
self.rar = None
|
||||||
|
|
||||||
###### File type handler api, used by rclexecm ---------->
|
###### File type handler api, used by rclexecm ---------->
|
||||||
def openfile(self, params):
|
def openfile(self, params):
|
||||||
self.currentindex = -1
|
self.currentindex = -1
|
||||||
@ -139,6 +142,7 @@ class RarExtractor:
|
|||||||
self.currentindex = 0
|
self.currentindex = 0
|
||||||
self.em.setmimetype('text/plain')
|
self.em.setmimetype('text/plain')
|
||||||
if len(self.rar.namelist()) == 0:
|
if len(self.rar.namelist()) == 0:
|
||||||
|
self.closefile()
|
||||||
eof = rclexecm.RclExecM.eofnext
|
eof = rclexecm.RclExecM.eofnext
|
||||||
else:
|
else:
|
||||||
eof = rclexecm.RclExecM.noteof
|
eof = rclexecm.RclExecM.noteof
|
||||||
@ -146,10 +150,14 @@ class RarExtractor:
|
|||||||
|
|
||||||
if self.currentindex >= len(self.rar.namelist()):
|
if self.currentindex >= len(self.rar.namelist()):
|
||||||
#self.em.rclog("getnext: EOF hit")
|
#self.em.rclog("getnext: EOF hit")
|
||||||
|
self.closefile()
|
||||||
return (False, "", "", rclexecm.RclExecM.eofnow)
|
return (False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
else:
|
else:
|
||||||
ret= self.extractone(self.rar.namelist()[self.currentindex])
|
ret = self.extractone(self.rar.namelist()[self.currentindex])
|
||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
|
if ret[3] == rclexecm.RclExecM.eofnext or \
|
||||||
|
ret[3] == rclexecm.RclExecM.eofnow:
|
||||||
|
self.closefile()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Main program: create protocol handler and extractor and run them
|
# Main program: create protocol handler and extractor and run them
|
||||||
|
|||||||
@ -42,6 +42,9 @@ class TarExtractor:
|
|||||||
iseof = rclexecm.RclExecM.eofnext
|
iseof = rclexecm.RclExecM.eofnext
|
||||||
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
|
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
|
||||||
|
|
||||||
|
def closefile(self):
|
||||||
|
self.tar = None
|
||||||
|
|
||||||
def openfile(self, params):
|
def openfile(self, params):
|
||||||
self.currentindex = -1
|
self.currentindex = -1
|
||||||
try:
|
try:
|
||||||
@ -71,6 +74,7 @@ class TarExtractor:
|
|||||||
self.currentindex = 0
|
self.currentindex = 0
|
||||||
self.em.setmimetype('text/plain')
|
self.em.setmimetype('text/plain')
|
||||||
if len(self.namen) == 0:
|
if len(self.namen) == 0:
|
||||||
|
self.closefile()
|
||||||
eof = rclexecm.RclExecM.eofnext
|
eof = rclexecm.RclExecM.eofnext
|
||||||
else:
|
else:
|
||||||
eof = rclexecm.RclExecM.noteof
|
eof = rclexecm.RclExecM.noteof
|
||||||
@ -78,10 +82,14 @@ class TarExtractor:
|
|||||||
|
|
||||||
if self.currentindex >= len(self.namen):
|
if self.currentindex >= len(self.namen):
|
||||||
self.namen=[]
|
self.namen=[]
|
||||||
|
self.closefile()
|
||||||
return (False, "", "", rclexecm.RclExecM.eofnow)
|
return (False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
else:
|
else:
|
||||||
ret= self.extractone(self.namen[self.currentindex])
|
ret = self.extractone(self.namen[self.currentindex])
|
||||||
self.currentindex += 1
|
self.currentindex += 1
|
||||||
|
if ret[3] == rclexecm.RclExecM.eofnext or \
|
||||||
|
ret[3] == rclexecm.RclExecM.eofnow:
|
||||||
|
self.closefile()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -13,15 +13,20 @@ class WarExtractor:
|
|||||||
|
|
||||||
def extractone(self, tarinfo):
|
def extractone(self, tarinfo):
|
||||||
docdata = ""
|
docdata = ""
|
||||||
|
iseof = rclexecm.RclExecM.noteof
|
||||||
try:
|
try:
|
||||||
member = self.tar.extractfile(tarinfo)
|
member = self.tar.extractfile(tarinfo)
|
||||||
docdata = member.read()
|
docdata = member.read()
|
||||||
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)
|
||||||
|
iseof = rclexecm.RclExecM.eofnow
|
||||||
ok = False
|
ok = False
|
||||||
return (ok, docdata, tarinfo.name, rclexecm.RclExecM.noteof)
|
return (ok, docdata, tarinfo.name, iseof)
|
||||||
|
|
||||||
|
def closefile():
|
||||||
|
self.tar = None
|
||||||
|
|
||||||
###### File type handler api, used by rclexecm ---------->
|
###### File type handler api, used by rclexecm ---------->
|
||||||
def openfile(self, params):
|
def openfile(self, params):
|
||||||
self.currentindex = -1
|
self.currentindex = -1
|
||||||
@ -50,9 +55,13 @@ class WarExtractor:
|
|||||||
tarinfo = self.tar.next()
|
tarinfo = self.tar.next()
|
||||||
if tarinfo is None:
|
if tarinfo is None:
|
||||||
#self.em.rclog("getnext: EOF hit")
|
#self.em.rclog("getnext: EOF hit")
|
||||||
|
self.closefile()
|
||||||
return (False, "", "", rclexecm.RclExecM.eofnow)
|
return (False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
else:
|
else:
|
||||||
ret = self.extractone(tarinfo)
|
ret = self.extractone(tarinfo)
|
||||||
|
if ret[3] == rclexecm.RclExecM.eofnext or \
|
||||||
|
ret[3] == rclexecm.RclExecM.eofnow:
|
||||||
|
self.closefile()
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
# Main program: create protocol handler and extractor and run them
|
# Main program: create protocol handler and extractor and run them
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user