From 32b1866fdd7e3413e2a405a29e6948ac9142c8a1 Mon Sep 17 00:00:00 2001 From: Louis Date: Tue, 25 Feb 2014 19:23:16 +0100 Subject: [PATCH] =?UTF-8?q?Mise=20en=20=C5=93uvre=20des=20options=20intera?= =?UTF-8?q?ctive=20et=20logger=20de=20buildsongbook.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #7 --- songbook.py | 9 +++++++-- songbook/build.py | 19 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/songbook.py b/songbook.py index 765815cb..b27a05af 100755 --- a/songbook.py +++ b/songbook.py @@ -7,6 +7,7 @@ import argparse import json import locale +import logging import os.path import textwrap import sys @@ -41,6 +42,10 @@ def argument_parser(args): def main(): """Main function:""" + # Logging configuration + logging.basicConfig(name = 'songbook') + logger = logging.getLogger('songbook') + # set script locale to match user's try: locale.setlocale(locale.LC_ALL, '') @@ -67,9 +72,9 @@ def main(): else: songbook['datadir'] = os.path.dirname(songbook_path) try: - buildsongbook(songbook, basename) + buildsongbook(songbook, basename, interactive = True, logger = logger) except errors.SongbookError as error: - print(error) + logger.error(error) sys.exit(1) sys.exit(0) diff --git a/songbook/build.py b/songbook/build.py index 16d8aba4..5d9acafa 100755 --- a/songbook/build.py +++ b/songbook/build.py @@ -3,12 +3,13 @@ """Build a songbook, according to parameters found in a .sb file.""" -from subprocess import call import codecs import glob import json +import logging import os.path import re +import subprocess import sys from songbook import __SHAREDIR__ @@ -224,13 +225,13 @@ def makeTexFile(sb, output): out.write(u''.join(content)) out.close() - -def buildsongbook(sb, basename): +def buildsongbook(sb, basename, interactive = False, logger = logging.getLogger()): """Build a songbook Arguments: - sb: Python representation of the .sb songbook configuration file. - basename: basename of the songbook to be built. + - interactive: in False, do not expect anything from stdin. """ 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(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 - if call(["pdflatex", "--shell-escape", texFile]): + if subprocess.call(["pdflatex"] + pdflatex_options + [texFile]): raise errors.LatexCompilationError(basename) # Make index sxdFiles = glob.glob("%s_*.sxd" % basename) for sxdFile in sxdFiles: - print "processing " + sxdFile + logger.info("processing " + sxdFile) idx = processSXD(sxdFile) indexFile = open(sxdFile[:-3] + "sbx", "w") indexFile.write(idx.entriesToStr().encode('utf8')) indexFile.close() # Second pdflatex pass - if call(["pdflatex", "--shell-escape", texFile]): + if subprocess.call(["pdflatex"] + pdflatex_options + [texFile]): raise errors.LatexCompilationError(basename) # Cleaning