From e9a09933476f27f6f83f72f4c34182f581562b36 Mon Sep 17 00:00:00 2001 From: David Bartley Date: Sat, 10 Nov 2007 03:58:28 -0500 Subject: [PATCH] Cleanup code --- scripts/xsltproc.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/scripts/xsltproc.py b/scripts/xsltproc.py index 07371aa..7b086d5 100755 --- a/scripts/xsltproc.py +++ b/scripts/xsltproc.py @@ -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)