|
@ -23,6 +23,7 @@ DEFAULT_AUTHWORDS = { |
|
|
"ignore": ["unknown"], |
|
|
"ignore": ["unknown"], |
|
|
"sep": ["and"], |
|
|
"sep": ["and"], |
|
|
} |
|
|
} |
|
|
|
|
|
DEFAULT_STEPS = ['tex', 'pdf', 'sbx', 'pdf', 'clean'] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable=too-few-public-methods |
|
|
# pylint: disable=too-few-public-methods |
|
@ -137,6 +138,7 @@ def clean(basename): |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
for ext in generated_extensions: |
|
|
for ext in generated_extensions: |
|
|
|
|
|
if os.path.isfile(basename + ext): |
|
|
try: |
|
|
try: |
|
|
os.unlink(basename + ext) |
|
|
os.unlink(basename + ext) |
|
|
except Exception as exception: |
|
|
except Exception as exception: |
|
@ -146,22 +148,28 @@ def clean(basename): |
|
|
def buildsongbook( |
|
|
def buildsongbook( |
|
|
raw_songbook, |
|
|
raw_songbook, |
|
|
basename, |
|
|
basename, |
|
|
|
|
|
steps=None, |
|
|
interactive=False, |
|
|
interactive=False, |
|
|
logger=logging.getLogger() |
|
|
logger=logging.getLogger(), |
|
|
): |
|
|
): |
|
|
"""Build a songbook |
|
|
"""Build a songbook |
|
|
|
|
|
|
|
|
Arguments: |
|
|
Arguments: |
|
|
- raw_songbook: Python representation of the .sb songbook configuration |
|
|
- raw_songbook: Python representation of the .sb songbook configuration |
|
|
file. |
|
|
file. |
|
|
|
|
|
- steps: list of steps to perform to compile songbook. Available steps are: |
|
|
|
|
|
- tex: build .tex file from templates; |
|
|
|
|
|
- pdf: compile .tex using pdflatex; |
|
|
|
|
|
- sbx: compile song and author indexes; |
|
|
|
|
|
- clean: remove temporary files. |
|
|
- 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. |
|
|
- interactive: in False, do not expect anything from stdin. |
|
|
""" |
|
|
""" |
|
|
|
|
|
|
|
|
songbook = Songbook(raw_songbook, basename) |
|
|
if steps is None: |
|
|
with codecs.open("{}.tex".format(basename), 'w', 'utf-8') as output: |
|
|
steps = DEFAULT_STEPS |
|
|
songbook.write_tex(output) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
songbook = Songbook(raw_songbook, basename) |
|
|
if not 'TEXINPUTS' in os.environ.keys(): |
|
|
if not 'TEXINPUTS' in os.environ.keys(): |
|
|
os.environ['TEXINPUTS'] = '' |
|
|
os.environ['TEXINPUTS'] = '' |
|
|
os.environ['TEXINPUTS'] += os.pathsep + os.path.join( |
|
|
os.environ['TEXINPUTS'] += os.pathsep + os.path.join( |
|
@ -179,10 +187,16 @@ def buildsongbook( |
|
|
if not interactive: |
|
|
if not interactive: |
|
|
pdflatex_options.append("-halt-on-error") |
|
|
pdflatex_options.append("-halt-on-error") |
|
|
|
|
|
|
|
|
# First pdflatex pass |
|
|
# Compilation |
|
|
|
|
|
for step in steps: |
|
|
|
|
|
if step == 'tex': |
|
|
|
|
|
# Building .tex file from templates |
|
|
|
|
|
with codecs.open("{}.tex".format(basename), 'w', 'utf-8') as output: |
|
|
|
|
|
songbook.write_tex(output) |
|
|
|
|
|
elif step == 'pdf': |
|
|
if subprocess.call(["pdflatex"] + pdflatex_options + [basename]): |
|
|
if subprocess.call(["pdflatex"] + pdflatex_options + [basename]): |
|
|
raise errors.LatexCompilationError(basename) |
|
|
raise errors.LatexCompilationError(basename) |
|
|
|
|
|
elif step == 'sbx': |
|
|
# Make index |
|
|
# Make index |
|
|
sxd_files = glob.glob("%s_*.sxd" % basename) |
|
|
sxd_files = glob.glob("%s_*.sxd" % basename) |
|
|
for sxd_file in sxd_files: |
|
|
for sxd_file in sxd_files: |
|
@ -191,10 +205,9 @@ def buildsongbook( |
|
|
index_file = open(sxd_file[:-3] + "sbx", "w") |
|
|
index_file = open(sxd_file[:-3] + "sbx", "w") |
|
|
index_file.write(idx.entries_to_str().encode('utf8')) |
|
|
index_file.write(idx.entries_to_str().encode('utf8')) |
|
|
index_file.close() |
|
|
index_file.close() |
|
|
|
|
|
elif step == 'clean': |
|
|
# Second pdflatex pass |
|
|
|
|
|
if subprocess.call(["pdflatex"] + pdflatex_options + [basename]): |
|
|
|
|
|
raise errors.LatexCompilationError(basename) |
|
|
|
|
|
|
|
|
|
|
|
# Cleaning |
|
|
# Cleaning |
|
|
clean(basename) |
|
|
clean(basename) |
|
|
|
|
|
else: |
|
|
|
|
|
# Unknown step name |
|
|
|
|
|
raise errors.UnknownStep(step) |
|
|