#!/usr/bin/env python """ azimuth.py - Azimuth Publishing Software Author: Sean B. Palmer, inamidst.com """ import sys, os, re title = 'Lo and Behold!' r_title = re.compile('
Not found!
' def articles(): mtime = os.path.getmtime names = [(mtime(fn), fn) for fn in os.listdir('.') if fn.endswith('.txt')] return sorted(names, reverse=True) def dispatcher(func): def outer(*args): args = (arg.strip('<>') for arg in args) def inner(m): kargs = {} groupdict = m.groupdict() for arg in args: if groupdict.has_key(arg): kargs[arg] = groupdict[arg] else: raise ValueError('No such group: %s' % arg) return func(**kargs) return inner return outer def articletitle(filename): f = open(filename) first = f.next() f.close() m = r_title.match(first) if m: return m.group(1) else: return title @dispatcher def article(**kargs): headers() name = kargs.get('name') text = name + '.txt' html = name + '.html' if os.path.isfile(text): render('src/head.html', title=articletitle(text)) render(text) render('src/tail.html') elif os.path.isfile(html): render('src/head.html', title=articletitle(html)) render(html) render('src/tail.html') @dispatcher def contents(**kargs): import datetime headers() render('src/head.html', title='Contents') print '