#!/usr/bin/env python #---------------------------------------------------------------------------- # Name: qdindex.py (Quick and dirty indexing) # Purpose: Generates index.html per directory from input files # Author: Huaiyu Zhu # Copyright: (C) 2000 Huaiyu Zhu, License: GNU GPL # Changes: # 2000-02-13 Initial version # 2000-03-09 public version 0.1.0 # Bugs: # Silently overwrites index.html if 00index.in and 00annot.in exist # Any unrecognized input line counts as empty line # $Id: qdindex.py,v 1.1 2000/07/22 20:48:28 hzhu Exp $ #---------------------------------------------------------------------------- """ This program is intended as a simple annotation tool for organizing directory listings. It accepts a list of directory names as arguments (default to '.' if empty). For each directory dir it generates a file dir/index.html if the input files dir/00annot.in and dir/00index.in exists. The input files contain paragraphs separated by empty lines. For 00annot.in, the first line becomes title, the second line contains the directory where 00tabs.in is located, the rest are introductory texts. The file 00tabs.in contains line-separated list of white-space-separated pairs of names and links to be displayed before title. For 00index.in, each paragraph becomes a table with a different bgcolor. Within each table each input line of the form "Topic" url url ... (where url can be a local path) becomes one row where the url are hyperlinked. If url/index.html exists it will be substituted as the link. It uses html style-sheets (css) for syntax highlighting. Any html tag can be embedded in the input files. """ #------------------------------------------------------------------ "All the formats" class ColorRotate: "Returns one of the colors per each call" colors = [ # "mintcream", # "lavenderblush", # "beige", # "aliceblue", # "linen", "lightcyan", "papayawhip", "lavender", "mistyrose", "palegoldenrod", "wheat", "gainsboro", "bisque", "peachpuff", "powderblue", "moccasin", ] i = 0 n = len(colors) def __call__(self): color = self.colors[self.i] self.i = self.i + 1 if self.i >= self.n: self.i = 0 return color color = ColorRotate() def print_head(title): print '
\n ' print '' % title def print_tabs(itemlist = []): print '
%s' % (ref, name) print ' |
%s
" %date
print ""
#------------------------------------------------------------------
"All the data"
"RE for parsing input data"
import re
entry = re.compile(r'"([^"]+)\s*"(.+)') # Cant use [!"]
par = re.compile(r'^\s*$')
"Files and directories"
import os.path
pathjoin = os.path.join
isfile = os.path.isfile
def existfile(path, dir, name):
"Test whether index exists in the pointed directory"
idx = pathjoin(dir, name)
pathidx = pathjoin(path, idx)
#print "" % pathidx
if isfile(pathidx): return idx
class Entry:
"Matched lines specify an entry {subj, dirlist}"
def __init__(self, entrymatch):
(self.subj, dirs) = entrymatch.groups()
self.dirlist = string.split(dirs)
def show(self, path):
print ' ", line) else: line = " " + line print string.rstrip(line) "Write index as tables" print_startindex() for line in lines: entrymatch = entry.match(line) if entrymatch: Entry(entrymatch).show(path) else: print_par() "Finishing up" print_tailer(date) #------------------------------------------------------------------ if __name__ == "__main__": #from os import environ from sys import argv if len(argv) < 2: dirs = ["."] else: dirs = argv[1:] print "Updating index in directories %s" % dirs for dir in dirs: print "---> Indexing %s" % dir dirindex(dir)