initial support for icalendar splitting
This commit is contained in:
parent
4c9268f23b
commit
744b8770fe
@ -1,3 +1,5 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
###########################################
|
###########################################
|
||||||
## Generic recoll multifilter communication code
|
## Generic recoll multifilter communication code
|
||||||
import sys
|
import sys
|
||||||
@ -6,12 +8,15 @@ import os
|
|||||||
class RclExecM:
|
class RclExecM:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.myname = os.path.basename(sys.argv[0])
|
self.myname = os.path.basename(sys.argv[0])
|
||||||
|
self.mimetype = ""
|
||||||
|
|
||||||
def rclog(self, s, doexit = 0, exitvalue = 1):
|
def rclog(self, s, doexit = 0, exitvalue = 1):
|
||||||
print >> sys.stderr, "RCLMFILT:", self.myname, ":", s
|
print >> sys.stderr, "RCLMFILT:", self.myname, ":", s
|
||||||
if doexit:
|
if doexit:
|
||||||
exit(exitvalue)
|
exit(exitvalue)
|
||||||
|
# Our worker sometimes knows the mime types of the data it sends
|
||||||
|
def setmimetype(self, mt):
|
||||||
|
self.mimetype = mt
|
||||||
def readparam(self):
|
def readparam(self):
|
||||||
s = sys.stdin.readline()
|
s = sys.stdin.readline()
|
||||||
if s == '':
|
if s == '':
|
||||||
@ -49,6 +54,10 @@ class RclExecM:
|
|||||||
print "Ipath:", len(ipath)
|
print "Ipath:", len(ipath)
|
||||||
sys.stdout.write(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 we're at the end of the contents, say so
|
||||||
if iseof:
|
if iseof:
|
||||||
print "Eof: 0"
|
print "Eof: 0"
|
||||||
|
|||||||
50
src/filters/rclics
Executable file
50
src/filters/rclics
Executable 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))
|
||||||
Loading…
x
Reference in New Issue
Block a user