Browse Source

Ne fait l'analyse des chansons que si nécessaire (#23)

pull/25/head
Louis 11 years ago
parent
commit
e4182dc456
  1. 16
      songbook_core/build.py

16
songbook_core/build.py

@ -58,7 +58,7 @@ class Songbook(object):
'datadir': os.path.abspath('.'), 'datadir': os.path.abspath('.'),
} }
self.songslist = None self.songslist = None
self._parse(raw_songbook) self._parse_raw(raw_songbook)
@staticmethod @staticmethod
def _set_songs_default(config): def _set_songs_default(config):
@ -82,7 +82,7 @@ class Songbook(object):
] + [',']) ] + [','])
] ]
def _parse(self, raw_songbook): def _parse_raw(self, raw_songbook):
"""Parse raw_songbook. """Parse raw_songbook.
The principle is: some special keys have their value processed; others The principle is: some special keys have their value processed; others
@ -90,7 +90,7 @@ class Songbook(object):
""" """
self.config.update(raw_songbook) self.config.update(raw_songbook)
self.config['datadir'] = os.path.abspath(self.config['datadir']) self.config['datadir'] = os.path.abspath(self.config['datadir'])
### Some post-processing
# Compute song list # Compute song list
if self.config['content'] is None: if self.config['content'] is None:
self.config['content'] = [ self.config['content'] = [
@ -104,20 +104,24 @@ class Songbook(object):
'*.sg', '*.sg',
) )
] ]
self.songslist = SongsList(self.config['datadir'])
self.songslist.append_list(self.config['content'])
# Ensure self.config['authwords'] contains all entries # Ensure self.config['authwords'] contains all entries
for (key, value) in DEFAULT_AUTHWORDS.items(): for (key, value) in DEFAULT_AUTHWORDS.items():
if key not in self.config['authwords']: if key not in self.config['authwords']:
self.config['authwords'][key] = value self.config['authwords'][key] = value
def _parse_songs(self):
"""Parse songs included in songbook."""
self.songslist = SongsList(self.config['datadir'])
self.songslist.append_list(self.config['content'])
def write_tex(self, output): def write_tex(self, output):
"""Build the '.tex' file corresponding to self. """Build the '.tex' file corresponding to self.
Arguments: Arguments:
- output: a file object, in which the file will be written. - output: a file object, in which the file will be written.
""" """
self._parse_songs()
renderer = TexRenderer( renderer = TexRenderer(
self.config['template'], self.config['template'],
self.config['datadir'], self.config['datadir'],
@ -217,7 +221,6 @@ class SongbookBuilder(object):
def build_tex(self): def build_tex(self):
"""Build .tex file from templates""" """Build .tex file from templates"""
self._run_once(self._set_latex)
with codecs.open( with codecs.open(
"{}.tex".format(self.basename), 'w', 'utf-8', "{}.tex".format(self.basename), 'w', 'utf-8',
) as output: ) as output:
@ -225,6 +228,7 @@ class SongbookBuilder(object):
def build_pdf(self): def build_pdf(self):
"""Build .pdf file from .tex file""" """Build .pdf file from .tex file"""
self._run_once(self._set_latex)
if subprocess.call( if subprocess.call(
["pdflatex"] + self._pdflatex_options + [self.basename] ["pdflatex"] + self._pdflatex_options + [self.basename]
): ):

Loading…
Cancel
Save