Implement members-this-term in xsltproc.py
* This removes the dependency on ceoquery
This commit is contained in:
parent
e9a0993347
commit
6ffc05609f
3
Makefile
3
Makefile
|
@ -10,13 +10,12 @@ common.mk: common.mk.in
|
||||||
echo 'ROOT = '`pwd` > $@
|
echo 'ROOT = '`pwd` > $@
|
||||||
cat $< >> $@
|
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
|
@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 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 ! -perm 2775 -print0 | xargs -r0 chmod 2775 || true
|
||||||
find ! -regex '.*/\..*' -type d ! -group www -print0 | xargs -r0 chgrp www || true
|
find ! -regex '.*/\..*' -type d ! -group www -print0 | xargs -r0 chgrp www || true
|
||||||
|
|
||||||
.PHONY: noroot
|
|
||||||
noroot:
|
noroot:
|
||||||
if test $$UID = 0; then echo "don't build as root!"; exit 1; fi
|
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 \
|
FILES = index.html exec.html members.html constitution.html donations.html \
|
||||||
donations.html constitution-change-20020920.html \
|
constitution-change-20020920.html constitution-change-20040205.html
|
||||||
constitution-change-20040205.html
|
|
||||||
RELDIR = about/
|
RELDIR = about/
|
||||||
include ../common.mk
|
include ../common.mk
|
||||||
|
|
||||||
$(OUTDIR)members.html: $(OUTDIR)members.xml
|
$(OUTDIR)members.html: force
|
||||||
|
|
||||||
.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(/&/, "\\&", name); gsub(/&/, "\\&", program); gsub(/"/, "\\"", name); gsub(/"/, "\\"", program); print "<member name=\"" name "\" program=\"" program "\" userid=\"" userid "\" />"; }' >> $@
|
|
||||||
echo '</memberlist>' >> $@
|
|
||||||
|
|
|
@ -8,14 +8,13 @@ else
|
||||||
endif
|
endif
|
||||||
OUTPUTS = $(addprefix $(OUTDIR),$(FILES))
|
OUTPUTS = $(addprefix $(OUTDIR),$(FILES))
|
||||||
|
|
||||||
.PHONY: mkoutdir
|
.PHONY: force mkoutdir build clean
|
||||||
|
|
||||||
mkoutdir:
|
mkoutdir:
|
||||||
mkdir -p $(OUTDIR)
|
mkdir -p $(OUTDIR)
|
||||||
|
|
||||||
.PHONY: build
|
|
||||||
build: $(OUTPUTS)
|
build: $(OUTPUTS)
|
||||||
|
|
||||||
.PHONY: clean
|
|
||||||
clean:
|
clean:
|
||||||
ifeq "$(ROOT)" "/users/www/www"
|
ifeq "$(ROOT)" "/users/www/www"
|
||||||
rm -rf $(OUTDIR)/*
|
rm -rf $(OUTDIR)/*
|
||||||
|
|
|
@ -1,39 +1,77 @@
|
||||||
#!/usr/bin/python2.4
|
#!/usr/bin/python2.4
|
||||||
import os, sys, urllib, libxml2, libxslt
|
import os, sys, urllib, libxml2, libxslt, ldap, time
|
||||||
|
|
||||||
#
|
#
|
||||||
# globals
|
# globals
|
||||||
#
|
#
|
||||||
cscUri = "http://csclub.uwaterloo.ca/xsltproc"
|
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
|
# csc:encode-for-uri
|
||||||
#
|
#
|
||||||
def cscEncodeForUri(ctx, str):
|
def cscEncodeForUri(ctx, arg):
|
||||||
if type(str) == type([]):
|
if type(arg) == type([]):
|
||||||
str = libxml2.xmlNode(str[0]).getContent()
|
arg = libxml2.xmlNode(arg[0]).getContent()
|
||||||
return urllib.quote(str)
|
return urllib.quote(arg)
|
||||||
|
|
||||||
#
|
#
|
||||||
# csc:term
|
# csc:term
|
||||||
#
|
#
|
||||||
def cscTerm(ctx, str):
|
def cscTerm(ctx, arg):
|
||||||
if type(str) == type([]):
|
if type(arg) == type([]):
|
||||||
str = libxml2.xmlNode(str[0]).getContent()
|
arg = libxml2.xmlNode(arg[0]).getContent()
|
||||||
try:
|
try:
|
||||||
[year, month, day] = str.split("-")
|
[year, month, day] = arg.split("-")
|
||||||
term = (int(month) - 1) / 4
|
term = (int(month) - 1) / 4
|
||||||
return terms[term] + " " + year
|
return cscTerms[term] + " " + year
|
||||||
except:
|
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
|
# csc:email
|
||||||
#
|
#
|
||||||
def cscEmail(ctx, str):
|
def cscEmail(ctx, arg):
|
||||||
if type(str) == type([]):
|
if type(arg) == type([]):
|
||||||
str = libxml2.xmlNode(str[0]).getContent()
|
str = libxml2.xmlNode(arg[0]).getContent()
|
||||||
return "_EMAIL_TODO_"
|
return "_EMAIL_TODO_"
|
||||||
|
|
||||||
#
|
#
|
||||||
|
@ -63,14 +101,15 @@ try:
|
||||||
# register extensions
|
# register extensions
|
||||||
libxslt.registerExtModuleFunction("encode-for-uri", cscUri, cscEncodeForUri)
|
libxslt.registerExtModuleFunction("encode-for-uri", cscUri, cscEncodeForUri)
|
||||||
libxslt.registerExtModuleFunction("term", cscUri, cscTerm)
|
libxslt.registerExtModuleFunction("term", cscUri, cscTerm)
|
||||||
|
libxslt.registerExtModuleFunction("member-list", cscUri, cscMemberList)
|
||||||
libxslt.registerExtModuleFunction("email", cscUri, cscEmail)
|
libxslt.registerExtModuleFunction("email", cscUri, cscEmail)
|
||||||
|
|
||||||
# parse xml/xslt and apply style-sheet
|
# parse xml/xslt and apply style-sheet
|
||||||
style = libxslt.parseStylesheetFile(xsltFile)
|
style = libxslt.parseStylesheetFile(xsltFile)
|
||||||
doc = libxml2.parseFile(inFile)
|
doc = libxml2.parseFile(inFile)
|
||||||
res = style.applyStylesheet(doc, params)
|
res = style.applyStylesheet(doc, params)
|
||||||
style.saveResultToFilename(outFile, res, 0)
|
ret = style.saveResultToFilename(outFile, res, 0)
|
||||||
|
|
||||||
except:
|
except Exception, e:
|
||||||
print "Unexpected error: '%s'" % sys.exc_info()[0]
|
print e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
<xsl:template match="members-this-term">
|
<xsl:template match="members-this-term">
|
||||||
<p>The members for <xsl:value-of select="csc:term($g_date)" /> are
|
<p>The members for <xsl:value-of select="csc:term($g_date)" /> are
|
||||||
listed here. We currently have
|
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>
|
members.</p>
|
||||||
<table>
|
<table>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -16,7 +16,7 @@
|
||||||
<th>Program</th>
|
<th>Program</th>
|
||||||
<th>Userid</th>
|
<th>Userid</th>
|
||||||
</tr>
|
</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:variable name="class">
|
||||||
<xsl:choose>
|
<xsl:choose>
|
||||||
<xsl:when test="position() mod 2 = 0">members1</xsl:when>
|
<xsl:when test="position() mod 2 = 0">members1</xsl:when>
|
||||||
|
|
Loading…
Reference in New Issue