Browse Source

Uniformisation de la gestion des log

Plus en conforme avec l'esprit de [logging](https://docs.python.org/2/library/logging.html)
pull/27/head
Louis 11 years ago
parent
commit
af2e68609a
  1. 4
      songbook
  2. 11
      songbook_core/build.py

4
songbook

@ -76,7 +76,7 @@ def main():
# Logging configuration # Logging configuration
logging.basicConfig(name='songbook', level=logging.INFO) logging.basicConfig(name='songbook', level=logging.INFO)
logger = logging.getLogger('songbook') logger = logging.getLogger(__name__)
# set script locale to match user's # set script locale to match user's
try: try:
@ -105,7 +105,7 @@ def main():
songbook['datadir'] = os.path.dirname(songbook_path) songbook['datadir'] = os.path.dirname(songbook_path)
try: try:
sb_builder = SongbookBuilder(songbook, basename, logger=logger) sb_builder = SongbookBuilder(songbook, basename)
sb_builder.interactive = True sb_builder.interactive = True
sb_builder.unsafe = True sb_builder.unsafe = True

11
songbook_core/build.py

@ -5,6 +5,7 @@
import codecs import codecs
import glob import glob
import logging
import os.path import os.path
import re import re
from subprocess import Popen, PIPE, call from subprocess import Popen, PIPE, call
@ -16,6 +17,7 @@ from songbook_core.index import process_sxd
from songbook_core.songs import Song, SongsList from songbook_core.songs import Song, SongsList
from songbook_core.templates import TexRenderer from songbook_core.templates import TexRenderer
LOGGER = logging.getLogger(__name__)
EOL = "\n" EOL = "\n"
DEFAULT_AUTHWORDS = { DEFAULT_AUTHWORDS = {
"after": ["by"], "after": ["by"],
@ -152,13 +154,11 @@ class SongbookBuilder(object):
# are function; values are return values of functions. # are function; values are return values of functions.
_called_functions = {} _called_functions = {}
def __init__(self, raw_songbook, basename, logger=None): def __init__(self, raw_songbook, basename):
# Representation of the .sb songbook configuration file. # Representation of the .sb songbook configuration file.
self.songbook = Songbook(raw_songbook, basename) self.songbook = Songbook(raw_songbook, basename)
# Basename of the songbook to be built. # Basename of the songbook to be built.
self.basename = basename self.basename = basename
# logging object to use
self.logger = logger
def _run_once(self, function, *args, **kwargs): def _run_once(self, function, *args, **kwargs):
"""Run function if it has not been run yet. """Run function if it has not been run yet.
@ -237,7 +237,7 @@ class SongbookBuilder(object):
while line: while line:
log += line log += line
line = p.stdout.readline() line = p.stdout.readline()
self.logger.info(log) LOGGER.info(log)
if p.returncode: if p.returncode:
raise errors.LatexCompilationError(self.basename) raise errors.LatexCompilationError(self.basename)
@ -246,8 +246,7 @@ class SongbookBuilder(object):
"""Make index""" """Make index"""
sxd_files = glob.glob("%s_*.sxd" % self.basename) sxd_files = glob.glob("%s_*.sxd" % self.basename)
for sxd_file in sxd_files: for sxd_file in sxd_files:
if self.logger: LOGGER.info("processing " + sxd_file)
self.logger.info("processing " + sxd_file)
idx = process_sxd(sxd_file) idx = process_sxd(sxd_file)
with open(sxd_file[:-3] + "sbx", "w") as index_file: with open(sxd_file[:-3] + "sbx", "w") as index_file:
index_file.write(idx.entries_to_str().encode('utf8')) index_file.write(idx.entries_to_str().encode('utf8'))

Loading…
Cancel
Save