initial support for icalendar splitting

This commit is contained in:
dockes 2009-10-22 17:13:29 +00:00
parent 4c9268f23b
commit 744b8770fe
2 changed files with 60 additions and 1 deletions

View File

@ -1,3 +1,5 @@
#!/usr/bin/env python
###########################################
## Generic recoll multifilter communication code
import sys
@ -6,12 +8,15 @@ import os
class RclExecM:
def __init__(self):
self.myname = os.path.basename(sys.argv[0])
self.mimetype = ""
def rclog(self, s, doexit = 0, exitvalue = 1):
print >> sys.stderr, "RCLMFILT:", self.myname, ":", s
if doexit:
exit(exitvalue)
# Our worker sometimes knows the mime types of the data it sends
def setmimetype(self, mt):
self.mimetype = mt
def readparam(self):
s = sys.stdin.readline()
if s == '':
@ -49,6 +54,10 @@ class RclExecM:
print "Ipath:", len(ipath)
sys.stdout.write(ipath)
if len(self.mimetype):
print "Mimetype:", len(self.mimetype)
sys.stdout.write(self.mimetype)
# If we're at the end of the contents, say so
if iseof:
print "Eof: 0"

50
src/filters/rclics Executable file
View File

@ -0,0 +1,50 @@
#!/usr/bin/env python
import rclexecm
from icalendar import Calendar, Event
class IcalExtractor:
def __init__(self, em):
self.file = ""
self.em = em
em.setmimetype("text/plain")
def extractone(self, index):
if index >= len(self.contents):
return(False, "", "", True)
docdata = self.contents[index].as_string()
#self.em.rclog(docdata)
eof = (self.currentindex >= len(self.contents) -1)
return (True, docdata, str(index), eof)
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
self.file = params["filename:"]
try:
self.cal = Calendar.from_string(open(self.file,'rb').read())
except:
return False
# Skip the top level object
self.currentindex = 1
self.contents = self.cal.walk()
return True
def getipath(self, params):
try:
index = int(params["ipath:"])
except:
return False
return self.extractone(index)
def getnext(self, params):
if self.currentindex >= len(self.contents):
#em.rclog("getnext: EOF hit")
return (False, "", "", 1)
else:
ret= self.extractone(self.currentindex)
self.currentindex += 1
return ret
e = rclexecm.RclExecM()
e.mainloop(IcalExtractor(e))