""" Replace pamphlet contents with embedded PDF $Id: ReplacePamphlet.py,v 0.2 2005/11/12 Bill Page $ TODO: 1) Provide a wiki folder property to override the path so that pamphlet, dvi, and pdf files can be mapped to specific directories. Currently defaults to 'imagesPath' for Zope/LatexWiki compatibility. But Apache proxy or additional Zope external files systems would allow them to be anywhere. 2) Write pamphlet file to source code archive and do a check-in Archive check-in controlled/disabled by a wiki folder property. """ import re, os, string from util import imagesPath, workingDir errorMessage = """\n
Some or all expressions may not have rendered properly, because Latex returned the following error:
%s
""" reConsts = re.MULTILINE+re.DOTALL def replacePamphlet(page,body): from pamphletWrapper import renderPDF # Keep the comments after the end of the document doc = re.match(r'^(\\.*?\\end{document})(.*)$',body,reConsts) if doc: # workingDir + fPath = fDir # + pageName = fName (physical location) # imagesPath + fPath + pageName = fUrl (logical location) # Note: only works with http://wiki.axiom-developer.org/... now # Need to fix this (somehow!) so that it works with url proxy aliases fPath = "/".join(page.wiki_base_url().split('/')[3:]) fDir = os.path.join(workingDir,fPath) try: os.makedirs(fDir) except: pass pageName = page.title_or_id() fName = os.path.join(fDir,pageName) try: file = open(fName+'.pamphlet', 'w') file.write(doc.group(1)) file.close() except: print "Can't save pamphlet file" raise pdf=re.match(r'.*\\usepackage\[.*(dvips|dvipdfm).*?\]{hyperref}',doc.group(1),reConsts) if pdf: pdfMethod=pdf.group(1) else: pdfMethod='' errors = renderPDF(fDir,pageName,pdfMethod) fUrl = os.path.join('/',imagesPath,fPath,pageName) return ('''
Download: pdf dvi ps src tex log

''' %(fUrl,fUrl,fUrl,fUrl,fUrl,fUrl, page.page_url(), '\n'+''.join(['\n'%(m.group(1)) for m in re.finditer(r'<<(.*?)>>=',doc.group(1)) if m.group(1)<>'*']), # we want * as default option fUrl)+ ((errors and """\n
Some or all of this page may not have rendered properly, because of the following error:
%s
""" %(errors)) or ''), doc.group(2)) else: # just comments return ('',body)