filter for gnu info files

This commit is contained in:
Jean-Francois Dockes 2010-10-30 17:26:00 +02:00
parent 5d29e7dcda
commit 9246d4e1bd
7 changed files with 38 additions and 37 deletions

View File

@ -29,11 +29,6 @@ htmltemplate = '''
</body> </body>
</html> </html>
''' '''
def htmlescape(txt):
txt = txt.replace("<", "&lt;")
txt = txt.replace("&", "&amp;")
txt = txt.replace('"', "&dquot;")
return txt
# mp3: album, title, artist, genre, date, tracknumber # mp3: album, title, artist, genre, date, tracknumber
# flac: album, title, artist, genre, xxx, tracknumber # flac: album, title, artist, genre, xxx, tracknumber
@ -42,6 +37,7 @@ class AudioTagExtractor:
def __init__(self, em): def __init__(self, em):
self.em = em self.em = em
self.currentindex = 0 self.currentindex = 0
self.em.setmimetype("text/html")
def extractone(self, params): def extractone(self, params):
#self.em.rclog("extractone %s %s" % (params["filename:"], params["mimetype:"])) #self.em.rclog("extractone %s %s" % (params["filename:"], params["mimetype:"]))
@ -69,18 +65,18 @@ class AudioTagExtractor:
artist = "" artist = ""
title = "" title = ""
try: try:
album = htmlescape(tags["album"][0].encode("utf-8")) album = self.em.htmlescape(tags["album"][0].encode("utf-8"))
except: except:
pass pass
try: try:
artist = htmlescape(tags["artist"][0].encode("utf-8")) artist = self.em.htmlescape(tags["artist"][0].encode("utf-8"))
except: except:
pass pass
try: try:
title = htmlescape(tags["title"][0].encode("utf-8")) title = self.em.htmlescape(tags["title"][0].encode("utf-8"))
except: except:
pass pass
alldata = htmlescape(tags.pprint().encode("utf-8")) alldata = self.em.htmlescape(tags.pprint().encode("utf-8"))
alldata = alldata.replace("\n", "<br>") alldata = alldata.replace("\n", "<br>")
docdata = htmltemplate % (album, artist, title, alldata) docdata = htmltemplate % (album, artist, title, alldata)
ok = True ok = True

View File

@ -18,6 +18,13 @@ class RclExecM:
print >> sys.stderr, "RCLMFILT:", self.myname, ":", s print >> sys.stderr, "RCLMFILT:", self.myname, ":", s
if doexit: if doexit:
sys.exit(exitvalue) sys.exit(exitvalue)
def htmlescape(self, txt):
txt = txt.replace("<", "&lt;")
txt = txt.replace("&", "&amp;")
txt = txt.replace('"', "&dquot;")
return txt
# Our worker sometimes knows the mime types of the data it sends # Our worker sometimes knows the mime types of the data it sends
def setmimetype(self, mt): def setmimetype(self, mt):
self.mimetype = mt self.mimetype = mt
@ -46,7 +53,7 @@ class RclExecM:
paramdata = "" paramdata = ""
#self.rclog("paramname [%s] paramsize %d value [%s]" % #self.rclog("paramname [%s] paramsize %d value [%s]" %
# (paramname, paramsize, paramdata)) # (paramname, paramsize, paramdata))
return (paramname, paramdata) return (paramname, paramdata)
# Send answer: document, ipath, possible eof. # Send answer: document, ipath, possible eof.

View File

@ -92,7 +92,7 @@ class IcalExtractor:
try: try:
index = int(params["ipath:"]) index = int(params["ipath:"])
except: except:
return False return (False, "", "", True)
return self.extractone(index) return self.extractone(index)
def getnext(self, params): def getnext(self, params):

View File

@ -44,7 +44,7 @@ class InfoExtractor:
iseof = rclexecm.RclExecM.noteof iseof = rclexecm.RclExecM.noteof
if self.currentindex >= len(self.contents) -1: if self.currentindex >= len(self.contents) -1:
iseof = rclexecm.RclExecM.eofnext iseof = rclexecm.RclExecM.eofnext
return (True, docdata, nodename, iseof) return (True, docdata, str(index), iseof)
###### File type handler api, used by rclexecm ----------> ###### File type handler api, used by rclexecm ---------->
def openfile(self, params): def openfile(self, params):
@ -77,16 +77,10 @@ class InfoExtractor:
# Extract specific node # Extract specific node
def getipath(self, params): def getipath(self, params):
try: try:
nodename = params["ipath:"] index = int(params["ipath:"])
except: except:
return False return (False, "", "", True)
return self.extractone(index)
# We could build a dictionary in the split function to avoid this.
# But it's used for preview, and the perf issue is minimal
for i in range(len(self.contents)):
if self.contents[i][0] == nodename:
return self.extractone(i)
return (False, "", "", True)
# Extract next in list # Extract next in list
def getnext(self, params): def getnext(self, params):
@ -109,7 +103,9 @@ class InfoSimpleSplitter:
node = "" node = ""
for line in fin: for line in fin:
if gotblankline and line.startswith("File: "): # It sometimes happens that info --subnodes produces a Node line
# beginning with spaces (it's a bug probably, only seen it once)
if gotblankline and line.lstrip(" ").startswith("File: "):
if index != 0: if index != 0:
listout.append((nodename, node)) listout.append((nodename, node))
line = line.rstrip("\n\r") line = line.rstrip("\n\r")
@ -120,8 +116,7 @@ class InfoSimpleSplitter:
for pair in pairs: for pair in pairs:
name, value = pair.split(':') name, value = pair.split(':')
name = name.strip(" ") name = name.strip(" ")
value = value.replace(":", " "); value = value.strip(" ")
value = value.replace("|", " ").strip(" ")
if name == "Node": if name == "Node":
nodename = value nodename = value
if name == "Up": if name == "Up":
@ -133,7 +128,6 @@ class InfoSimpleSplitter:
print >> sys.stderr, "Info file", filename, \ print >> sys.stderr, "Info file", filename, \
"Dup node: ", nodename "Dup node: ", nodename
node_dict[nodename] = up node_dict[nodename] = up
print "NODE ", nodename, "UP ", up
node = "" node = ""
index += 1 index += 1
@ -149,21 +143,21 @@ class InfoSimpleSplitter:
listout.append((nodename, node)) listout.append((nodename, node))
# Compute node paths (concatenate "Up" values), to be used # Compute node paths (concatenate "Up" values), to be used
# as page titles and ipaths. It's unfortunate that this will crash if # as page titles. It's unfortunate that this will crash if
# the info file tree is bad # the info file tree is bad
listout1 = [] listout1 = []
for nodename, node in listout: for nodename, node in listout:
ipath = "" title = ""
loop = 0 loop = 0
error = 0 error = 0
while nodename != "Top": while nodename != "Top":
ipath = nodename + " / " + ipath title = nodename + " / " + title
if node_dict.has_key(nodename): if node_dict.has_key(nodename):
nodename = node_dict[nodename] nodename = node_dict[nodename]
else: else:
print >> sys.stderr, \ print >> sys.stderr, \
"Infofile: node's Up does not exist: file %s, path %s, up [%s]" % \ "Infofile: node's Up does not exist: file %s, path %s, up [%s]" % \
(infofile, ipath, nodename) (infofile, title, nodename)
error = 1 error = 1
break break
loop += 1 loop += 1
@ -176,12 +170,12 @@ class InfoSimpleSplitter:
if error: if error:
continue continue
if ipath == "": if title == "":
ipath = infofile title = infofile
else: else:
ipath = infofile + " / " + ipath title = infofile + " / " + title
ipath = ipath.rstrip(" / ") title = title.rstrip(" / ")
listout1.append((ipath, node)) listout1.append((title, node))
return listout1 return listout1

View File

@ -68,6 +68,7 @@ application/x-abiword = exec rclabw
application/x-awk = internal application/x-awk = internal
application/x-dvi = exec rcldvi application/x-dvi = exec rcldvi
application/x-flac = execm rclaudio application/x-flac = execm rclaudio
application/x-gnuinfo = execm rclinfo
application/x-kword = exec rclkwd application/x-kword = exec rclkwd
application/x-lyx = exec rcllyx application/x-lyx = exec rcllyx
application/x-perl = internal application/x-perl = internal
@ -137,6 +138,7 @@ application/x-fsdirectory = folder
application/x-kword = wordprocessing application/x-kword = wordprocessing
application/x-lyx = wordprocessing application/x-lyx = wordprocessing
application/x-scribus = document application/x-scribus = document
application/x-gnuinfo = document
application/x-tex = wordprocessing application/x-tex = wordprocessing
application/x-awk = source application/x-awk = source
application/x-perl = source application/x-perl = source
@ -182,6 +184,7 @@ text = \
application/x-lyx \ application/x-lyx \
application/x-perl \ application/x-perl \
application/x-scribus \ application/x-scribus \
application/x-gnuinfo \
application/x-shellscript \ application/x-shellscript \
application/x-tex \ application/x-tex \
image/vnd.djvu \ image/vnd.djvu \

View File

@ -89,7 +89,7 @@
.lyx = application/x-lyx .lyx = application/x-lyx
.sla = application/x-scribus .sla = application/x-scribus
.scd = application/x-scribus .scd = application/x-scribus
.info = application/x-gnuinfo
.kwd = application/x-kword .kwd = application/x-kword
.wpd = application/vnd.wordperfect .wpd = application/vnd.wordperfect

View File

@ -45,10 +45,11 @@ application/vnd.sun.xml.writer = openoffice %f
application/vnd.sun.xml.writer.global = openoffice %f application/vnd.sun.xml.writer.global = openoffice %f
application/vnd.sun.xml.writer.template = openoffice %f application/vnd.sun.xml.writer.template = openoffice %f
application/vnd.wordperfect = openoffice %f application/vnd.wordperfect = openoffice %f
application/x-chm = okular %f application/x-chm = kchmviewer %f
application/x-dvi = xdvi %f application/x-dvi = xdvi %f
application/x-fsdirectory = rox %f application/x-fsdirectory = rox %f
application/x-flac = xmms %f application/x-flac = xmms %f
application/x-gnuinfo = xterm -e "info -f %f"
application/x-lyx = lyx %f application/x-lyx = lyx %f
application/x-scribus = scribus %f application/x-scribus = scribus %f
application/x-tex = gnuclient -q %f application/x-tex = gnuclient -q %f