Merge pull request #245 from jwgcarlson/issue-183-multiple-pdfs
Allow for multiple LaTeX sources and/or PDF images.rtd2
commit
31bd5f9ddd
|
@ -1,5 +1,4 @@
|
|||
from glob import glob
|
||||
import re
|
||||
import os
|
||||
import logging
|
||||
|
||||
|
@ -10,9 +9,6 @@ from projects.utils import run
|
|||
from core.utils import copy_file_to_app_servers
|
||||
|
||||
|
||||
latex_re = re.compile('the LaTeX files are in (.*)\.')
|
||||
pdf_re = re.compile('Output written on (.+) \(')
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
class Builder(BaseBuilder):
|
||||
|
@ -32,27 +28,39 @@ class Builder(BaseBuilder):
|
|||
|
||||
if latex_results[0] == 0:
|
||||
os.chdir('_build/latex')
|
||||
tex_globs = glob('*.tex')
|
||||
if tex_globs:
|
||||
tex_file = tex_globs[0]
|
||||
pdf_results = run('pdflatex -interaction=nonstopmode %s' % tex_file)
|
||||
pdf_match = pdf_re.search(pdf_results[1])
|
||||
if pdf_match:
|
||||
if project.whitelisted:
|
||||
# For whitelisted projects, read LaTeX sources from conf.py
|
||||
conf_py_file = project.conf_file(self.version.slug)
|
||||
conf = {}
|
||||
execfile(conf_py_file, conf, conf)
|
||||
tex_files = [d[1] for d in conf.get('latex_documents', [])]
|
||||
else:
|
||||
# Otherwise treat all .tex files as sources
|
||||
tex_files = glob('*.tex')
|
||||
|
||||
# Run LaTeX -> PDF conversions
|
||||
pdflatex_cmds = ['pdflatex -interaction=nonstopmode %s' % tex_file
|
||||
for tex_file in tex_files]
|
||||
pdf_results = run(*pdflatex_cmds)
|
||||
|
||||
if pdf_results[0] == 0:
|
||||
for tex_file in tex_files:
|
||||
to_path = os.path.join(settings.MEDIA_ROOT,
|
||||
'pdf',
|
||||
project.slug,
|
||||
self.version.slug)
|
||||
from_globs = glob(os.path.join(os.getcwd(), "*.pdf"))
|
||||
if from_globs:
|
||||
from_file = from_globs[0]
|
||||
to_file = os.path.join(to_path, '%s.pdf' % project.slug)
|
||||
if getattr(settings, "MULTIPLE_APP_SERVERS", None):
|
||||
copy_file_to_app_servers(from_file, to_file)
|
||||
else:
|
||||
if not os.path.exists(to_path):
|
||||
os.makedirs(to_path)
|
||||
run('mv -f %s %s' % (from_file, to_file))
|
||||
else:
|
||||
to_file = os.path.join(to_path, '%s.pdf' % project.slug)
|
||||
# pdflatex names its output predictably: foo.tex -> foo.pdf
|
||||
pdf_filename = os.path.splitext(tex_file)[0] + '.pdf'
|
||||
from_file = os.path.join(os.getcwd(), pdf_filename)
|
||||
if getattr(settings, "MULTIPLE_APP_SERVERS", None):
|
||||
copy_file_to_app_servers(from_file, to_file)
|
||||
else:
|
||||
if not os.path.exists(to_path):
|
||||
os.makedirs(to_path)
|
||||
run('mv -f %s %s' % (from_file, to_file))
|
||||
|
||||
if latex_results[0] != 0 or pdf_results[0] != 0:
|
||||
log.warning("PDF Building failed. Moving on.")
|
||||
return (latex_results, pdf_results)
|
||||
|
||||
|
|
Loading…
Reference in New Issue