#!/usr/bin/env python """ Convert Eph Format Author: Sean B. Palmer, inamidst.com Credit: Suggested by Cody Woodard. """ import cgitb; cgitb.enable() import os import pwk SCRIPT_NAME = os.environ.get('SCRIPT_NAME') REQUEST_URI = os.environ.get('REQUEST_URI') def text(page): import textwrap f = open(page + '.html') text = pwk.wikify(f.read()) f.close() print "Content-Type: text/plain" print for line in text.splitlines(): if len(line) > 79: for wrappedline in textwrap.wrap(line, width=79): print wrappedline else: print line def convert(uri): parts = uri.split('/') format = parts.pop() page = parts.pop() formats = {'text': text} formats[format](page) def source(): print "Content-Type: text/plain" print fn = os.path.join(os.environ.get('DOCUMENT_ROOT'), '.' + SCRIPT_NAME) f = open(fn) print f.read() f.close() def main(uri=None): uri = uri or REQUEST_URI scriptpath, ext = os.path.splitext(SCRIPT_NAME) if REQUEST_URI == scriptpath: source() else: convert(uri) if __name__=="__main__": main()