2009-10-07 08:46:21 -04:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# File: all.py
|
|
|
|
# Version: 0.1
|
|
|
|
# Description: a renewed XEP compilation tool
|
|
|
|
# Last Modified: 2009
|
|
|
|
# Author: Tobias Markmann (tm@ayena.de)
|
|
|
|
# License: public domain
|
|
|
|
# HowTo: ./all.py
|
|
|
|
|
|
|
|
## LICENSE ##
|
|
|
|
#
|
|
|
|
# Copyright (c) 1999 - 2009 XMPP Standards Foundation
|
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
# of this software and associated documentation files (the "Software"), to deal
|
|
|
|
# in the Software without restriction, including without limitation the rights
|
|
|
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
# copies of the Software, and to permit persons to whom the Software is
|
|
|
|
# furnished to do so, subject to the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be included in
|
|
|
|
# all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
# THE SOFTWARE.
|
|
|
|
#
|
|
|
|
## END LICENSE ##
|
|
|
|
|
|
|
|
import pickle
|
|
|
|
import commands
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
import getopt
|
2009-10-08 09:55:32 -04:00
|
|
|
import glob
|
2009-10-07 08:46:21 -04:00
|
|
|
|
|
|
|
XEPPATH = "/var/www/vhosts/xmpp.org/extensions"
|
|
|
|
BUILDDICT = "/var/xsf/xepbuild.dict"
|
|
|
|
|
2009-10-07 15:29:47 -04:00
|
|
|
VERBOSE = False
|
2009-10-07 08:46:21 -04:00
|
|
|
last_build = {}
|
|
|
|
|
|
|
|
def filebase( filename ):
|
|
|
|
return os.path.splitext(os.path.basename(filename))[0]
|
|
|
|
|
|
|
|
|
2009-10-07 15:29:47 -04:00
|
|
|
def checkError( error, desc):
|
|
|
|
global verbose
|
|
|
|
|
|
|
|
if error != 0:
|
|
|
|
if verbose:
|
|
|
|
print "Error: ", desc
|
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
2009-10-07 08:46:21 -04:00
|
|
|
def fileHash( filename ):
|
|
|
|
f = open(filename, "rb")
|
|
|
|
import hashlib
|
|
|
|
h = hashlib.sha1()
|
|
|
|
h.update(f.read())
|
|
|
|
hash = h.hexdigest()
|
|
|
|
f.close()
|
|
|
|
return hash
|
|
|
|
|
|
|
|
def loadDict( filename ):
|
|
|
|
try:
|
|
|
|
f = open(filename, "rb")
|
|
|
|
di = pickle.load(f)
|
|
|
|
f.close()
|
|
|
|
return di
|
|
|
|
except:
|
|
|
|
print "failed loading dict."
|
|
|
|
return {}
|
|
|
|
|
|
|
|
def saveDict( filename, di ):
|
|
|
|
f = open(filename, "w")
|
|
|
|
pickle.dump(di, f)
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
def buildXHTML( file ):
|
|
|
|
nr = re.match("xep-(\d\d\d\d).xml", file).group(1)
|
|
|
|
error, desc = commands.getstatusoutput("xsltproc xep.xsl xep-" + nr + ".xml > " + XEPPATH + "/xep-" + nr + ".html")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("xsltproc ref.xsl xep-" + nr + ".xml > " + XEPPATH + "/refs/reference.XSF.XEP-" + nr + ".xml")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("xsltproc examples.xsl xep-" + nr + ".xml > " + XEPPATH + "/examples/" + nr + ".xml")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput(" cp xep-" + nr + ".xml " + XEPPATH + "/")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
|
|
def buildPDF( file ):
|
|
|
|
nr = re.match("xep-(\d\d\d\d).xml", file).group(1)
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("xsltproc -o /tmp/xepbuilder/xep-" + nr + ".tex.xml xep2texml.xsl xep-" + nr + ".xml")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("texml -e utf8 /tmp/xepbuilder/xep-" + nr + ".tex.xml /tmp/xepbuilder/xep-" + nr + ".tex")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
#detect http urls and escape them to make them breakable
|
|
|
|
error, desc = commands.getstatusoutput('''sed -i 's|\([\s"]\)\(http://[^ "]*\)|\1\\path{\2}|g' /tmp/xepbuilder/xep-''' + nr + ".tex")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
#adjust references
|
|
|
|
error, desc = commands.getstatusoutput('''sed -i 's|\\hyperref\[#\([^}]*\)\]|\\hyperref\[\1\]|g' /tmp/xepbuilder/xep-''' + nr + ".tex")
|
|
|
|
if error != 0:
|
2009-10-07 14:47:59 -04:00
|
|
|
if verbose == 1:
|
|
|
|
print "Error: ", desc
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput('''sed -i 's|\\pageref{#\([^}]*\)}|\\pageref{\1}|g' /tmp/xepbuilder/xep-''' + nr + ".tex")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
olddir = os.getcwd()
|
|
|
|
os.chdir("/tmp/xepbuilder")
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("xelatex -interaction=batchmode xep-" + nr + ".tex")
|
2009-10-08 09:55:32 -04:00
|
|
|
#if not checkError(error, desc):
|
|
|
|
# os.chdir(olddir)
|
|
|
|
# return False
|
2009-10-07 08:46:21 -04:00
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("xelatex -interaction=batchmode xep-" + nr + ".tex")
|
2009-10-08 09:55:32 -04:00
|
|
|
#if not checkError(error, desc):
|
|
|
|
# os.chdir(olddir)
|
|
|
|
# return False
|
2009-10-07 08:46:21 -04:00
|
|
|
|
|
|
|
os.chdir(olddir)
|
|
|
|
|
|
|
|
error, desc = commands.getstatusoutput("cp /tmp/xepbuilder/xep-" + nr + ".pdf " + XEPPATH + "/")
|
2009-10-07 15:29:47 -04:00
|
|
|
if not checkError(error, desc):
|
2009-10-07 08:46:21 -04:00
|
|
|
return False
|
|
|
|
|
|
|
|
return True
|
|
|
|
|
|
|
|
def buildXEP( filename ):
|
|
|
|
print "Building " + filename + ": ",
|
|
|
|
if buildXHTML( filename ):
|
|
|
|
print "XHTML(OK) / ",
|
|
|
|
else:
|
|
|
|
print "XHTML(ERROR) / ",
|
|
|
|
|
|
|
|
if buildPDF( filename ):
|
|
|
|
print "PDF(OK)"
|
|
|
|
else:
|
|
|
|
print "PDF(ERROR)"
|
|
|
|
|
2009-10-08 09:55:32 -04:00
|
|
|
def buildAll():
|
|
|
|
files = glob.glob('xep-????.xml')
|
2009-10-08 11:29:29 -04:00
|
|
|
files.sort(key=lambda x: x.lower())
|
2009-10-08 09:55:32 -04:00
|
|
|
for file in files:
|
|
|
|
buildXEP( file )
|
|
|
|
|
2009-10-07 14:51:56 -04:00
|
|
|
def usage():
|
|
|
|
print "gen.py: generate nice XHTML and beatuy PDF out of the XEP XML"
|
|
|
|
print ""
|
|
|
|
print "Usage:"
|
|
|
|
print "gen.py xep-####.xml"
|
|
|
|
print ""
|
|
|
|
print "Options:"
|
|
|
|
print "-v Enable verbose output for debugging."
|
|
|
|
|
2009-10-07 08:46:21 -04:00
|
|
|
def main(argv):
|
2009-10-07 15:29:47 -04:00
|
|
|
global verbose
|
2009-10-08 09:55:32 -04:00
|
|
|
buildall = False
|
2009-10-07 15:29:47 -04:00
|
|
|
|
2009-10-07 08:46:21 -04:00
|
|
|
try:
|
2009-10-08 09:55:32 -04:00
|
|
|
options, remainder = getopt.gnu_getopt(argv, "va")
|
2009-10-07 08:46:21 -04:00
|
|
|
except getopt.GetoptError:
|
2009-10-07 14:51:56 -04:00
|
|
|
usage()
|
2009-10-07 08:46:21 -04:00
|
|
|
sys.exit(2)
|
|
|
|
|
2009-10-07 08:54:59 -04:00
|
|
|
for opt, arg in options:
|
2009-10-07 15:29:47 -04:00
|
|
|
if opt in ('-v'):
|
|
|
|
verbose = True
|
2009-10-08 09:55:32 -04:00
|
|
|
elif opt in ('-a'):
|
|
|
|
buildall = True
|
|
|
|
|
|
|
|
if len(remainder) > 0:
|
|
|
|
xep = remainder[0]
|
2009-10-07 08:46:21 -04:00
|
|
|
|
|
|
|
last_build = loadDict(BUILDDICT)
|
|
|
|
|
|
|
|
commands.getstatusoutput("rm /tmp/xepbuilder")
|
|
|
|
commands.getstatusoutput("mkdir /tmp/xepbuilder")
|
2009-10-07 13:48:05 -04:00
|
|
|
commands.getstatusoutput("cp ../images/xmpp.pdf /tmp/xepbuilder/xmpp.pdf")
|
|
|
|
commands.getstatusoutput("cp ../images/xmpp-text.pdf /tmp/xepbuilder/xmpp-text.pdf")
|
2009-10-07 08:46:21 -04:00
|
|
|
|
2009-10-08 09:55:32 -04:00
|
|
|
if buildall:
|
|
|
|
buildAll()
|
|
|
|
else:
|
|
|
|
buildXEP( xep )
|
2009-10-07 08:46:21 -04:00
|
|
|
|
|
|
|
saveDict(BUILDDICT, last_build)
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv[1:])
|