filter for gnu info files
This commit is contained in:
parent
5d29e7dcda
commit
9246d4e1bd
@ -29,11 +29,6 @@ htmltemplate = '''
|
||||
</body>
|
||||
</html>
|
||||
'''
|
||||
def htmlescape(txt):
|
||||
txt = txt.replace("<", "<")
|
||||
txt = txt.replace("&", "&")
|
||||
txt = txt.replace('"', "&dquot;")
|
||||
return txt
|
||||
|
||||
# mp3: album, title, artist, genre, date, tracknumber
|
||||
# flac: album, title, artist, genre, xxx, tracknumber
|
||||
@ -42,7 +37,8 @@ class AudioTagExtractor:
|
||||
def __init__(self, em):
|
||||
self.em = em
|
||||
self.currentindex = 0
|
||||
|
||||
self.em.setmimetype("text/html")
|
||||
|
||||
def extractone(self, params):
|
||||
#self.em.rclog("extractone %s %s" % (params["filename:"], params["mimetype:"]))
|
||||
docdata = ""
|
||||
@ -69,18 +65,18 @@ class AudioTagExtractor:
|
||||
artist = ""
|
||||
title = ""
|
||||
try:
|
||||
album = htmlescape(tags["album"][0].encode("utf-8"))
|
||||
album = self.em.htmlescape(tags["album"][0].encode("utf-8"))
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
artist = htmlescape(tags["artist"][0].encode("utf-8"))
|
||||
artist = self.em.htmlescape(tags["artist"][0].encode("utf-8"))
|
||||
except:
|
||||
pass
|
||||
try:
|
||||
title = htmlescape(tags["title"][0].encode("utf-8"))
|
||||
title = self.em.htmlescape(tags["title"][0].encode("utf-8"))
|
||||
except:
|
||||
pass
|
||||
alldata = htmlescape(tags.pprint().encode("utf-8"))
|
||||
alldata = self.em.htmlescape(tags.pprint().encode("utf-8"))
|
||||
alldata = alldata.replace("\n", "<br>")
|
||||
docdata = htmltemplate % (album, artist, title, alldata)
|
||||
ok = True
|
||||
|
||||
@ -18,6 +18,13 @@ class RclExecM:
|
||||
print >> sys.stderr, "RCLMFILT:", self.myname, ":", s
|
||||
if doexit:
|
||||
sys.exit(exitvalue)
|
||||
|
||||
def htmlescape(self, txt):
|
||||
txt = txt.replace("<", "<")
|
||||
txt = txt.replace("&", "&")
|
||||
txt = txt.replace('"', "&dquot;")
|
||||
return txt
|
||||
|
||||
# Our worker sometimes knows the mime types of the data it sends
|
||||
def setmimetype(self, mt):
|
||||
self.mimetype = mt
|
||||
@ -46,7 +53,7 @@ class RclExecM:
|
||||
paramdata = ""
|
||||
|
||||
#self.rclog("paramname [%s] paramsize %d value [%s]" %
|
||||
# (paramname, paramsize, paramdata))
|
||||
# (paramname, paramsize, paramdata))
|
||||
return (paramname, paramdata)
|
||||
|
||||
# Send answer: document, ipath, possible eof.
|
||||
|
||||
@ -92,7 +92,7 @@ class IcalExtractor:
|
||||
try:
|
||||
index = int(params["ipath:"])
|
||||
except:
|
||||
return False
|
||||
return (False, "", "", True)
|
||||
return self.extractone(index)
|
||||
|
||||
def getnext(self, params):
|
||||
|
||||
@ -44,7 +44,7 @@ class InfoExtractor:
|
||||
iseof = rclexecm.RclExecM.noteof
|
||||
if self.currentindex >= len(self.contents) -1:
|
||||
iseof = rclexecm.RclExecM.eofnext
|
||||
return (True, docdata, nodename, iseof)
|
||||
return (True, docdata, str(index), iseof)
|
||||
|
||||
###### File type handler api, used by rclexecm ---------->
|
||||
def openfile(self, params):
|
||||
@ -77,16 +77,10 @@ class InfoExtractor:
|
||||
# Extract specific node
|
||||
def getipath(self, params):
|
||||
try:
|
||||
nodename = params["ipath:"]
|
||||
index = int(params["ipath:"])
|
||||
except:
|
||||
return False
|
||||
|
||||
# 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)
|
||||
return (False, "", "", True)
|
||||
return self.extractone(index)
|
||||
|
||||
# Extract next in list
|
||||
def getnext(self, params):
|
||||
@ -109,7 +103,9 @@ class InfoSimpleSplitter:
|
||||
node = ""
|
||||
|
||||
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:
|
||||
listout.append((nodename, node))
|
||||
line = line.rstrip("\n\r")
|
||||
@ -120,8 +116,7 @@ class InfoSimpleSplitter:
|
||||
for pair in pairs:
|
||||
name, value = pair.split(':')
|
||||
name = name.strip(" ")
|
||||
value = value.replace(":", " ");
|
||||
value = value.replace("|", " ").strip(" ")
|
||||
value = value.strip(" ")
|
||||
if name == "Node":
|
||||
nodename = value
|
||||
if name == "Up":
|
||||
@ -133,7 +128,6 @@ class InfoSimpleSplitter:
|
||||
print >> sys.stderr, "Info file", filename, \
|
||||
"Dup node: ", nodename
|
||||
node_dict[nodename] = up
|
||||
print "NODE ", nodename, "UP ", up
|
||||
node = ""
|
||||
index += 1
|
||||
|
||||
@ -149,21 +143,21 @@ class InfoSimpleSplitter:
|
||||
listout.append((nodename, node))
|
||||
|
||||
# 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
|
||||
listout1 = []
|
||||
for nodename, node in listout:
|
||||
ipath = ""
|
||||
title = ""
|
||||
loop = 0
|
||||
error = 0
|
||||
while nodename != "Top":
|
||||
ipath = nodename + " / " + ipath
|
||||
title = nodename + " / " + title
|
||||
if node_dict.has_key(nodename):
|
||||
nodename = node_dict[nodename]
|
||||
else:
|
||||
print >> sys.stderr, \
|
||||
"Infofile: node's Up does not exist: file %s, path %s, up [%s]" % \
|
||||
(infofile, ipath, nodename)
|
||||
(infofile, title, nodename)
|
||||
error = 1
|
||||
break
|
||||
loop += 1
|
||||
@ -176,12 +170,12 @@ class InfoSimpleSplitter:
|
||||
if error:
|
||||
continue
|
||||
|
||||
if ipath == "":
|
||||
ipath = infofile
|
||||
if title == "":
|
||||
title = infofile
|
||||
else:
|
||||
ipath = infofile + " / " + ipath
|
||||
ipath = ipath.rstrip(" / ")
|
||||
listout1.append((ipath, node))
|
||||
title = infofile + " / " + title
|
||||
title = title.rstrip(" / ")
|
||||
listout1.append((title, node))
|
||||
|
||||
return listout1
|
||||
|
||||
|
||||
@ -68,6 +68,7 @@ application/x-abiword = exec rclabw
|
||||
application/x-awk = internal
|
||||
application/x-dvi = exec rcldvi
|
||||
application/x-flac = execm rclaudio
|
||||
application/x-gnuinfo = execm rclinfo
|
||||
application/x-kword = exec rclkwd
|
||||
application/x-lyx = exec rcllyx
|
||||
application/x-perl = internal
|
||||
@ -137,6 +138,7 @@ application/x-fsdirectory = folder
|
||||
application/x-kword = wordprocessing
|
||||
application/x-lyx = wordprocessing
|
||||
application/x-scribus = document
|
||||
application/x-gnuinfo = document
|
||||
application/x-tex = wordprocessing
|
||||
application/x-awk = source
|
||||
application/x-perl = source
|
||||
@ -182,6 +184,7 @@ text = \
|
||||
application/x-lyx \
|
||||
application/x-perl \
|
||||
application/x-scribus \
|
||||
application/x-gnuinfo \
|
||||
application/x-shellscript \
|
||||
application/x-tex \
|
||||
image/vnd.djvu \
|
||||
|
||||
@ -89,7 +89,7 @@
|
||||
.lyx = application/x-lyx
|
||||
.sla = application/x-scribus
|
||||
.scd = application/x-scribus
|
||||
|
||||
.info = application/x-gnuinfo
|
||||
.kwd = application/x-kword
|
||||
|
||||
.wpd = application/vnd.wordperfect
|
||||
|
||||
@ -45,10 +45,11 @@ application/vnd.sun.xml.writer = openoffice %f
|
||||
application/vnd.sun.xml.writer.global = openoffice %f
|
||||
application/vnd.sun.xml.writer.template = openoffice %f
|
||||
application/vnd.wordperfect = openoffice %f
|
||||
application/x-chm = okular %f
|
||||
application/x-chm = kchmviewer %f
|
||||
application/x-dvi = xdvi %f
|
||||
application/x-fsdirectory = rox %f
|
||||
application/x-flac = xmms %f
|
||||
application/x-gnuinfo = xterm -e "info -f %f"
|
||||
application/x-lyx = lyx %f
|
||||
application/x-scribus = scribus %f
|
||||
application/x-tex = gnuclient -q %f
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user