\n%s"
% (term, level * DL_LEVEL_INDENT))
append("\n%s- %s%s"
% (level * DL_LEVEL_INDENT, node.links[0], node.text[-1]))
for link in node.links[1:]:
append(",\n%s %s[Link]" % (level * DL_LEVEL_INDENT, link))
previous = current
append("\n")
append("
" * (level + 1))
append("\n\n")
return string.join(strings, '')
def format_letter(letter):
if letter == '.':
lettername = ". (dot)"
elif letter == '_':
lettername = "_ (underscore)"
else:
lettername = string.upper(letter)
return "\n
\n\n\n" \
% (letter, lettername)
def format_html(nodes):
letter_groups = split_letters(nodes)
items = []
for letter, nodes in letter_groups:
s = "%s" % (letter, letter)
items.append(s)
s = ["
\n%s\n" % string.join(items, " |\n")]
for letter, nodes in letter_groups:
s.append(format_letter(letter))
s.append(format_nodes(nodes))
return string.join(s, '')
def collapse(nodes):
"""Collapse sequences of nodes with matching keys into a single node.
Destructive."""
if len(nodes) < 2:
return
prev = nodes[0]
i = 1
while i < len(nodes):
node = nodes[i]
if not node.cmp_entry(prev):
prev.links.append(node.links[0])
del nodes[i]
else:
i = i + 1
prev = node
def dump(nodes, fp):
for node in nodes:
fp.write(node.dump())
def main():
import getopt
ifn = "-"
ofn = "-"
opts, args = getopt.getopt(sys.argv[1:], "o:", ["output="])
for opt, val in opts:
if opt in ("-o", "--output"):
ofn = val
if not args:
args = [ifn]
nodes = []
for fn in args:
nodes = nodes + load(open(fn))
nodes.sort()
collapse(nodes)
html = format_html(nodes)
if ofn == "-":
sys.stdout.write(html)
else:
open(ofn, "w").write(html)
if __name__ == "__main__":
main()