From 265e6ec09f7cedc17699cf52f83fa13e348375e6 Mon Sep 17 00:00:00 2001 From: Guido Draheim Date: Sun, 25 Mar 2018 23:16:36 +0200 Subject: [PATCH] generate overview html pages --- docs/dbk2man.py | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/docs/dbk2man.py b/docs/dbk2man.py index 9f38871..0327841 100755 --- a/docs/dbk2man.py +++ b/docs/dbk2man.py @@ -11,6 +11,7 @@ __author__ = "Guido U. Draheim" import logging import os.path import re +import collections import xml.etree.ElementTree as ET logg = logging.getLogger("dbk2man") @@ -35,18 +36,17 @@ def htm(text): text = text.replace('"', '"') return text +OverviewEntry = collections.namedtuple("OverviewEntry", ["manpage", "manvolnum", "refpurpose"]) + def parse_docbook(filename): tree = ET.parse(filename) return tree.getroot() def dbk2(man, filenames, subdirectory = "."): - indexed = [] for filename in filenames: root = parse_docbook(filename) overview = docbook2(man, root, subdirectory) overview2(man, overview, subdirectory, filename) - indexed.append((filename, overview)) - indexed2(man, indexed, subdirectory, "index") def docbook2(man, root, subdirectory = "."): if root.tag != "reference": @@ -63,12 +63,10 @@ def docbook2(man, root, subdirectory = "."): logg.warning("found <%s> instead", refentry.tag) continue overviewref = refentry2(man, refentry, subdirectory, title) - for refname, refpurpose in overviewref.items(): - overview[refname] = refpurpose + for filename, overviewentry in overviewref.items(): + overview[filename] = overviewentry return overview - - def refentryinfo2(man, refentry, title): date, productname, manvolnum, refentrytitle = "", "", "", "" section = refentry.find("refentryinfo") @@ -401,14 +399,34 @@ def refentry2(man, refentry, subdirectory = ".", title = ""): # overview = {} for manpage in manpages: - overview["%s(%s)" % (manpage, manvolnum)] = refpurpose + entry = OverviewEntry(manpage, manvolnum, refpurpose) + overview[filename] = entry return overview -def overview2(man, overview, subdirectory, filename): - pass +def splitname(filename): + base = os.path.basename(filename) + name, ext = os.path.splitext(base) + return name + +def overview2(man, overview, subdirectory, docbook_filename): + if not man: + overview2htm(overview, subdirectory, docbook_filename) -def indexed2(man, indexed, subdirectory, filebase): - pass +def overview2htm(overview, subdirectory, docbook_filename): + basename = splitname(docbook_filename) + text = "%s %s\n" % (htm(basename), htm("overview")) + text += "\n" + text += "

%s %s

\n" % (htm(basename), htm("overview")) + text += "\n" + text += "\n" + filename = "%s/%s.%s" % (subdirectory, basename, "html") + writefile(filename, text) def writefile(filename, manpagetext): dirname = os.path.dirname(filename) -- 2.40.0