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 argparse
import json import json
import locale import locale
import logging
import os.path import os.path
import textwrap import textwrap
import sys import sys
@ -41,6 +42,10 @@ def argument_parser(args):
def main(): def main():
"""Main function:""" """Main function:"""
# Logging configuration
logging.basicConfig(name = 'songbook')
logger = logging.getLogger('songbook')
# set script locale to match user's # set script locale to match user's
try: try:
locale.setlocale(locale.LC_ALL, '') locale.setlocale(locale.LC_ALL, '')
@ -67,9 +72,9 @@ def main():
else: else:
songbook['datadir'] = os.path.dirname(songbook_path) songbook['datadir'] = os.path.dirname(songbook_path)
try: try:
buildsongbook(songbook, basename) buildsongbook(songbook, basename, interactive = True, logger = logger)
except errors.SongbookError as error: except errors.SongbookError as error:
print(error) logger.error(error)
sys.exit(1) sys.exit(1)
sys.exit(0) sys.exit(0)

19
songbook/build.py

@ -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

Loading…
Cancel
Save