#!/usr/bin/python

import os, sys, string

# Make HTML definition lists based on files and readmes.
# Takes directories as arguments and only include files for which there 
# exist an according readme file. Files are listed as definition terms, 
# with hypertext link, the content of the readme is listed as definition 
# declaration.  
#
# Kolbjørn Barmen <kolla@nvg.org>, November 1999


def filefilter(name):
	if name[-7:] == '.readme':
		return 1
	else:
		return None

if len(sys.argv) < 2:
		print "Usage: deflist.py <PATH> [PATH]..."
		
for dir in sys.argv[1:]:
	filelist = filter(filefilter, os.listdir(dir))

	sys.stdout.write('<dl>\n')

	for name in filelist:
		file = dir+'/'+name
		sys.stdout.write('<dt><a href="'+file[:-7]+'">'+name[:-7]+'</a>\n')
		fil = open(file)
		text = fil.readlines()
		sys.stdout.write('<dd>')
		for line in text:
			line = string.rstrip(line)
			sys.stdout.write(line+'<br>\n')

	sys.stdout.write('</dl>\n')
