#!/usr/bin/env python # Horribly hacked-together script to generate an HTML index page for # Haddock-generated Haskell package docs. Note that the docs # directory is hard-coded, below: see the comments there. import os import re import StringIO # This is the path to the docs. Any subdirectory which contains an # 'html/index.html' will get an entry in the index (all the other are # listed separately at the end). # The index is written to 'index.html' at this path. PATH = "/usr/local/share/doc" class Package: def __init__(self, name, path): self.name = name self.path = path self.title = self._seekTitle() def __cmp__(self, other): return cmp(self.name.lower(), other.name.lower()) def index(self): return os.path.join(self.path, 'html', 'index.html') titleRE = r'>.*: (.*)\n') s.write('\n') s.write('Local Haskell package docs (from Haddock)\n') s.write(('\n')) s.write('\n') s.write('\n') s.write('

Local packages with docs

\n') split = self.splitAlpha() keys = split.keys() keys.sort() s.write('

\n') links = ['%s' % (start, start) for start in keys] s.write(' • '.join(links)) s.write('

\n') for start in keys: packages = split[start] s.write('

%s

\n' % (start, start)) s.write(' \n') s.write('
') s.write('

Directories without HTML docs

\n') s.write('\n') s.write('\n') s.write('\n') h = s.getvalue() return h def splitAlpha(self): al = {} for package in self.has_html: start = package.name[0].upper() try: al[start].append(package) except KeyError: al[start] = [package] return al def seek_html(self, path): items = os.listdir(path) if 'html' not in items: return False html = os.path.join(path, 'html') if not os.path.isdir(html): return False return 'index.html' in os.listdir(html) if __name__ == '__main__': builder = Builder(PATH)