Browse Source

Mise en œuvre des options interactive et logger de buildsongbook.

Closes #7
pull/20/head
Louis 11 years ago
parent
commit
32b1866fdd
  1. 9
      songbook.py
  2. 19
      songbook/build.py

9
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)

19
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

Loading…
Cancel
Save