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