Implement members-this-term in xsltproc.py

* This removes the dependency on ceoquery
foo
David Bartley 15 years ago
parent e9a0993347
commit 6ffc05609f
  1. 3
      Makefile
  2. 15
      about/Makefile
  3. 5
      common.mk.in
  4. 75
      scripts/xsltproc.py
  5. 4
      xsl/members.xsl

@ -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

@ -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 '<?xml version='\''1.0'\''?>' > $@
echo '<memberlist>' >> $@
ceoquery memberlist | sort | awk -F \| '{ name = $$1; program = $$2; userid = $$3; gsub(/&/, "\\&amp;", name); gsub(/&/, "\\&amp;", program); gsub(/"/, "\\&quot;", name); gsub(/"/, "\\&quot;", program); print "<member name=\"" name "\" program=\"" program "\" userid=\"" userid "\" />"; }' >> $@
echo '</memberlist>' >> $@
$(OUTDIR)members.html: force

@ -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)/*

@ -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)

@ -8,7 +8,7 @@
<xsl:template match="members-this-term">
<p>The members for <xsl:value-of select="csc:term($g_date)" /> are
listed here. We currently have
<xsl:value-of select="count(document(concat($g_outdir, 'members.xml'))/memberlist/member)" />
<xsl:value-of select="count(csc:member-list('')/member)" />
members.</p>
<table>
<tr>
@ -16,7 +16,7 @@
<th>Program</th>
<th>Userid</th>
</tr>
<xsl:for-each select="document(concat($g_outdir, 'members.xml'))/memberlist/member">
<xsl:for-each select="csc:member-list('')/member">
<xsl:variable name="class">
<xsl:choose>
<xsl:when test="position() mod 2 = 0">members1</xsl:when>

Loading…
Cancel
Save