diff --git a/Makefile b/Makefile index 0a0b4bb..c0b6bf6 100644 --- a/Makefile +++ b/Makefile @@ -10,13 +10,12 @@ common.mk: common.mk.in echo 'ROOT = '`pwd` > $@ cat $< >> $@ -build: noroot mkoutdir common.mk $(OUTPUTS) +build: noroot mkoutdir common.mk $(OUTPUTS) force @for i in $(SUBDIRS) ; do cd $$i && ($(MAKE) || exit 1) && cd .. ; done find ! -regex '.*/\..*' -type f ! -perm -0664 -print0 | xargs -r0 chmod u=rwX,g=rwX,o=rX || true find ! -regex '.*/\..*' -type d ! -perm 2775 -print0 | xargs -r0 chmod 2775 || true find ! -regex '.*/\..*' -type d ! -group www -print0 | xargs -r0 chgrp www || true -.PHONY: noroot noroot: if test $$UID = 0; then echo "don't build as root!"; exit 1; fi diff --git a/about/Makefile b/about/Makefile index 2b0eba4..63e10bd 100644 --- a/about/Makefile +++ b/about/Makefile @@ -1,15 +1,6 @@ -FILES = members.xml index.html exec.html members.html constitution.html \ - donations.html constitution-change-20020920.html \ - constitution-change-20040205.html +FILES = index.html exec.html members.html constitution.html donations.html \ + constitution-change-20020920.html constitution-change-20040205.html RELDIR = about/ include ../common.mk -$(OUTDIR)members.html: $(OUTDIR)members.xml - -.PHONY: $(OUTDIR)members.xml -$(OUTDIR)members.xml: - test -e /usr/bin/ceoquery || (echo 'Erorr: ceoquery not found'; exit 1) - echo '' > $@ - echo '' >> $@ - ceoquery memberlist | sort | awk -F \| '{ name = $$1; program = $$2; userid = $$3; gsub(/&/, "\\&", name); gsub(/&/, "\\&", program); gsub(/"/, "\\"", name); gsub(/"/, "\\"", program); print ""; }' >> $@ - echo '' >> $@ +$(OUTDIR)members.html: force diff --git a/common.mk.in b/common.mk.in index 61c39fe..5fd354a 100644 --- a/common.mk.in +++ b/common.mk.in @@ -8,14 +8,13 @@ else endif OUTPUTS = $(addprefix $(OUTDIR),$(FILES)) -.PHONY: mkoutdir +.PHONY: force mkoutdir build clean + mkoutdir: mkdir -p $(OUTDIR) -.PHONY: build build: $(OUTPUTS) -.PHONY: clean clean: ifeq "$(ROOT)" "/users/www/www" rm -rf $(OUTDIR)/* diff --git a/scripts/xsltproc.py b/scripts/xsltproc.py index 7b086d5..30d3a52 100755 --- a/scripts/xsltproc.py +++ b/scripts/xsltproc.py @@ -1,39 +1,77 @@ #!/usr/bin/python2.4 -import os, sys, urllib, libxml2, libxslt +import os, sys, urllib, libxml2, libxslt, ldap, time # # globals # cscUri = "http://csclub.uwaterloo.ca/xsltproc" -terms = ["Winter", "Spring", "Fall"] +cscTerms = ["Winter", "Spring", "Fall"] +cscShortTerms = ['w', 's', 'f'] +cscLdapUri = "ldap://ldap1.csclub.uwaterloo.ca ldap://ldap2.csclub.uwaterloo.ca" +cscLdap = None +cscPeopleBase = 'ou=People,dc=csclub,dc=uwaterloo,dc=ca' + +# +# cscLdapConnect +# +def cscLdapConnect(): + global cscLdap + cscLdap = ldap.initialize(cscLdapUri) + cscLdap.simple_bind_s("", "") # # csc:encode-for-uri # -def cscEncodeForUri(ctx, str): - if type(str) == type([]): - str = libxml2.xmlNode(str[0]).getContent() - return urllib.quote(str) +def cscEncodeForUri(ctx, arg): + if type(arg) == type([]): + arg = libxml2.xmlNode(arg[0]).getContent() + return urllib.quote(arg) # # csc:term # -def cscTerm(ctx, str): - if type(str) == type([]): - str = libxml2.xmlNode(str[0]).getContent() +def cscTerm(ctx, arg): + if type(arg) == type([]): + arg = libxml2.xmlNode(arg[0]).getContent() try: - [year, month, day] = str.split("-") + [year, month, day] = arg.split("-") term = (int(month) - 1) / 4 - return terms[term] + " " + year + return cscTerms[term] + " " + year except: - print "Invalid term '%s'" % str + print "Invalid term '%s'" % arg + +# +# csc:member-list +# +def cscMemberList(ctx, arg): + try: + if cscLdap == None: + cscLdapConnect() + curDate = time.strftime('%d-%m-%Y') + year = time.localtime().tm_year + term = cscShortTerms[int(time.localtime().tm_mon - 1) / 4] + members = cscLdap.search_s(cscPeopleBase, ldap.SCOPE_SUBTREE, + '(&(objectClass=member)(term=%s%d))' % (term, year)) + doc = libxml2.newDoc("1.0") + root = doc.newChild(None, "memberlist", None) + for (_, member) in members: + node = root.newChild(None, "member", None) + node.setProp("userid", member['uid'][0]) + node.setProp("name", member['cn'][0]) + if not 'program' in member: + member['program'] = [''] + node.setProp("program", member['program'][0]) + return [root] + except Exception, e: + print e + raise # # csc:email # -def cscEmail(ctx, str): - if type(str) == type([]): - str = libxml2.xmlNode(str[0]).getContent() +def cscEmail(ctx, arg): + if type(arg) == type([]): + str = libxml2.xmlNode(arg[0]).getContent() return "_EMAIL_TODO_" # @@ -63,14 +101,15 @@ try: # register extensions libxslt.registerExtModuleFunction("encode-for-uri", cscUri, cscEncodeForUri) libxslt.registerExtModuleFunction("term", cscUri, cscTerm) + libxslt.registerExtModuleFunction("member-list", cscUri, cscMemberList) libxslt.registerExtModuleFunction("email", cscUri, cscEmail) # parse xml/xslt and apply style-sheet style = libxslt.parseStylesheetFile(xsltFile) doc = libxml2.parseFile(inFile) res = style.applyStylesheet(doc, params) - style.saveResultToFilename(outFile, res, 0) + ret = style.saveResultToFilename(outFile, res, 0) -except: - print "Unexpected error: '%s'" % sys.exc_info()[0] +except Exception, e: + print e sys.exit(1) diff --git a/xsl/members.xsl b/xsl/members.xsl index 1aaebea..d2fdc06 100644 --- a/xsl/members.xsl +++ b/xsl/members.xsl @@ -8,7 +8,7 @@

The members for are listed here. We currently have - + members.

@@ -16,7 +16,7 @@ - + members1
Program Userid