/usr/share/doc/devhelp/tools/html2funcs.py is in devhelp 3.18.1-1ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 | #!/usr/bin/env python
import formatter
import htmllib
import sgmllib
import string
import sys
import os.path
import os
SKIP_DATA = [ "Next Page", "Previous Page", "Home", "Next", "Up", "<", ">"]
class HTMLParser (htmllib.HTMLParser):
is_a = 0
a = []
link = ""
def anchor_bgn (self, href, name, type):
self.is_a = 1
self.link = href
def anchor_end (self):
self.is_a = 0
def handle_data (self, data):
data = string.strip (data)
if data in SKIP_DATA:
return
if not '#' in self.link:
return
if self.link[:2] == "..":
return
if self.is_a and self.link:
self.a.append ((data, self.link))
def parse_file (filename, bookname):
fd = open (filename)
try:
p = HTMLParser (formatter.NullFormatter())
p.feed (fd.read())
p.close()
except KeyboardInterrupt:
raise SystemExit
return p.a
dirname = os.path.abspath (sys.argv[1])
bookname = os.path.basename (os.path.abspath (sys.argv[1]))
files = os.listdir (dirname)
files.sort()
funcs = []
for file in files:
if file[-5:] != ".html":
continue
print "parsing", file
links = parse_file (dirname + "/" + file, bookname)
for link in links:
if not link in funcs:
funcs.append (link)
print "Sorting function list"
funcs.sort()
filename = "%s/%s.index" % (dirname, bookname)
print "Writing index to", filename
fd = open (filename, "w")
fd.write ("<functions>\n")
for name, link in funcs:
if ' ' in name or '\n' in name:
continue
fd.write (' <function name="%s" link="%s"/>\n' % (name, link))
fd.write ("</functions>\n</book>\n")
fd.close()
|