#!/usr/bin/python
### This template generates a Python script.
###
### It must output a file that is executable as a python cgi script.
###
###(ie: has a .py or .cgi extension and is located in a script
### alias directory, and is chmod'ed to 755 with the containing
### directory chmod'ed to 755).
"""Template Index Generator for Python
Generates an HTML index for downloading Movable Type Template files
"""
import sys
import StringIO
import os
from os import listdir
from os.path import join, splitext
# Directory where are templates are stored
dir = "/home/joshstaiger/joshstaiger.org/mttemplates"
# Base url where templates can be accessed on site
url = "/mttemplates"
# Template file extensions (dot ommitted)
exts = [".html", ".xml", ".rdf", ".tmpl", ".css"]
# Template categories
catgs = ["index", "archive", "special", "module"]
# Category display names
catgDisp = {"index":"Index Templates",
"archive":"Archive-Related Templates",
"special":"Special Templates",
"module":"Template Modules"}
# Template display names
tmplDisp = {"index/atom.xml":"Atom Index",
"index/categoryarchives.html":"Category Archive Index",
"index/index.html":"Main Index",
"index/archives":"Monthly Archive Index",
"index/rsd.xml":"RSD",
"index/index.rdf":"RSS 1.0 Index",
"index/index.xml":"RSS 2.0 Index",
"index/sitemap.html":"Site Map",
"index/styles-site.css":"Stylesheet",
"archive/category.html":"Category Archive",
"archive/date-based.html":"Date-Based Archive",
"archive/individual.html":"Individual Entry Archive",
"special/comment-listing.html":"Comment Listing Template",
"special/comment-preview.html":"Comment Preview Template",
"special/comment-error.html":"Comment Error Template",
"special/comment-pending.html":"Comment Pending Template",
"special/trackback-listing.html":"TrackBack Listing Template",
"special/uploaded-image.html":"Uploaded Image Popup Template",
"special/dynamic-pages-error.html":"Dynamic Pages Error Template",
"module/rememberme.html":"Remember Me"}
def displayCatg(string):
"""Return the display string for the specified category.
Looks up string in the catgDisp dictionary. If present then we
return the corresponding value, otherwise we simply re-return the string.
"""
if(catgDisp.has_key(string)):
return catgDisp[string]
else:
return string
def displayTmpl(string):
"""Return the display string for the specified template.
Looks up string in the tmplDisp dictionary. If present then we
return the corresponding value, otherwise we return the basename
of the specified string (os.path.basename) with its extension stripped.
"""
if(tmplDisp.has_key(string)):
return tmplDisp[string]
else:
name = os.path.basename(string)
return stripext(name)
def stripext(filename):
"""Strip the extension from the specified filename"""
return splitext(filename)[0]
def templateIndex():
saveout = sys.stdout
try:
sys.stdout = StringIO.StringIO()
for catg in catgs:
print "
", displayCatg(catg), "
"
print "\n"
finally:
s = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = saveout
return s
print """Content-Type: text/html; charset=ISO-8859-1
Movable Type Templates for Josh Staiger's Personal Site
<$MTInclude module="defaultmeta"$>
<$MTInclude module="alternatesmeta"$>
<$MTInclude module="skiptonav"$>
Given that I have borrowed liberally from ideas elsewhere on the
Internet when comming up with the design for this site (namely from Mark Pilgrim, and Philip Greenspun), I am giving
something back by making the Movable Type templates
for this site freely available.
The following templates should work in MovableType 3.0 or greater.
All templates are licensed under Creative Commons
Attribution. Feel free to borrow ideas contained in them for your
own site.
"""
print templateIndex()
print """
<$MTInclude module="footer"$>
"""