Cleanup code

This commit is contained in:
David Bartley 2007-11-10 03:58:28 -05:00
parent 0293fa9d4c
commit e9a0993347
1 changed files with 14 additions and 19 deletions

View File

@ -1,10 +1,11 @@
#!/usr/bin/python2.4
import os, sys, re, urllib, libxml2, libxslt
import os, sys, urllib, libxml2, libxslt
#
# globals
#
cscUri = "http://csclub.uwaterloo.ca/xsltproc"
terms = ["Winter", "Spring", "Fall"]
#
# csc:encode-for-uri
@ -20,26 +21,19 @@ def cscEncodeForUri(ctx, str):
def cscTerm(ctx, str):
if type(str) == type([]):
str = libxml2.xmlNode(str[0]).getContent()
try:
# YYYY-MM-DD
(year, month, day) = re.findall("^([0-9]+)-([0-9]+)-([0-9]+)$", str)[0]
month = int(month)
if month >= 1 and month <= 4:
return "Winter " + year
elif month >= 5 and month <= 8:
return "Spring " + year
elif month >= 9 and month <= 12:
return "Fall " + year
else:
print "Invalid month '" + month + "'"
[year, month, day] = str.split("-")
term = (int(month) - 1) / 4
return terms[term] + " " + year
except:
print "Invalid term '" + str + "'"
print "Invalid term '%s'" % str
#
# csc:email
#
def cscEmail(ctx, str):
if type(str) == type([]):
str = libxml2.xmlNode(str[0]).getContent()
return "_EMAIL_TODO_"
#
@ -58,11 +52,12 @@ rawParams = sys.argv[4:]
# check params
params = {}
for p in rawParams:
p = p.split("=")
if len(p) == 1:
print "Missing value for parameter " + p[0]
try:
[key, val] = p.split("=")
params[key] = "'" + val + "'"
except:
print "Missing value for parameter '%s'" % p
sys.exit(1)
params[p[0]] = "'" + p[1] + "'"
try:
# register extensions
@ -77,5 +72,5 @@ try:
style.saveResultToFilename(outFile, res, 0)
except:
print "Unexpected error:", sys.exc_info()[0]
print "Unexpected error: '%s'" % sys.exc_info()[0]
sys.exit(1)