|
@ -3,12 +3,13 @@ |
|
|
|
|
|
|
|
|
"""Build a songbook, according to parameters found in a .sb file.""" |
|
|
"""Build a songbook, according to parameters found in a .sb file.""" |
|
|
|
|
|
|
|
|
from subprocess import call |
|
|
|
|
|
import codecs |
|
|
import codecs |
|
|
import glob |
|
|
import glob |
|
|
import json |
|
|
import json |
|
|
|
|
|
import logging |
|
|
import os.path |
|
|
import os.path |
|
|
import re |
|
|
import re |
|
|
|
|
|
import subprocess |
|
|
import sys |
|
|
import sys |
|
|
|
|
|
|
|
|
from songbook import __SHAREDIR__ |
|
|
from songbook import __SHAREDIR__ |
|
@ -224,13 +225,13 @@ def makeTexFile(sb, output): |
|
|
out.write(u''.join(content)) |
|
|
out.write(u''.join(content)) |
|
|
out.close() |
|
|
out.close() |
|
|
|
|
|
|
|
|
|
|
|
def buildsongbook(sb, basename, interactive = False, logger = logging.getLogger()): |
|
|
def buildsongbook(sb, basename): |
|
|
|
|
|
"""Build a songbook |
|
|
"""Build a songbook |
|
|
|
|
|
|
|
|
Arguments: |
|
|
Arguments: |
|
|
- sb: Python representation of the .sb songbook configuration file. |
|
|
- sb: Python representation of the .sb songbook configuration file. |
|
|
- basename: basename of the songbook to be built. |
|
|
- basename: basename of the songbook to be built. |
|
|
|
|
|
- interactive: in False, do not expect anything from stdin. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
texFile = basename + ".tex" |
|
|
texFile = basename + ".tex" |
|
@ -243,21 +244,27 @@ def buildsongbook(sb, basename): |
|
|
os.environ['TEXINPUTS'] += os.pathsep + os.path.join(__SHAREDIR__, 'latex') |
|
|
os.environ['TEXINPUTS'] += os.pathsep + os.path.join(__SHAREDIR__, 'latex') |
|
|
os.environ['TEXINPUTS'] += os.pathsep + os.path.join(sb['datadir'], 'latex') |
|
|
os.environ['TEXINPUTS'] += os.pathsep + os.path.join(sb['datadir'], 'latex') |
|
|
|
|
|
|
|
|
|
|
|
# pdflatex options |
|
|
|
|
|
pdflatex_options = [] |
|
|
|
|
|
pdflatex_options.append("--shell-escape") # Lilypond compilation |
|
|
|
|
|
if not interactive: |
|
|
|
|
|
pdflatex_options.append("-halt-on-error") |
|
|
|
|
|
|
|
|
# First pdflatex pass |
|
|
# First pdflatex pass |
|
|
if call(["pdflatex", "--shell-escape", texFile]): |
|
|
if subprocess.call(["pdflatex"] + pdflatex_options + [texFile]): |
|
|
raise errors.LatexCompilationError(basename) |
|
|
raise errors.LatexCompilationError(basename) |
|
|
|
|
|
|
|
|
# Make index |
|
|
# Make index |
|
|
sxdFiles = glob.glob("%s_*.sxd" % basename) |
|
|
sxdFiles = glob.glob("%s_*.sxd" % basename) |
|
|
for sxdFile in sxdFiles: |
|
|
for sxdFile in sxdFiles: |
|
|
print "processing " + sxdFile |
|
|
logger.info("processing " + sxdFile) |
|
|
idx = processSXD(sxdFile) |
|
|
idx = processSXD(sxdFile) |
|
|
indexFile = open(sxdFile[:-3] + "sbx", "w") |
|
|
indexFile = open(sxdFile[:-3] + "sbx", "w") |
|
|
indexFile.write(idx.entriesToStr().encode('utf8')) |
|
|
indexFile.write(idx.entriesToStr().encode('utf8')) |
|
|
indexFile.close() |
|
|
indexFile.close() |
|
|
|
|
|
|
|
|
# Second pdflatex pass |
|
|
# Second pdflatex pass |
|
|
if call(["pdflatex", "--shell-escape", texFile]): |
|
|
if subprocess.call(["pdflatex"] + pdflatex_options + [texFile]): |
|
|
raise errors.LatexCompilationError(basename) |
|
|
raise errors.LatexCompilationError(basename) |
|
|
|
|
|
|
|
|
# Cleaning |
|
|
# Cleaning |
|
|