From afffdb19b168362cc0b392cb095a4d23498c57af Mon Sep 17 00:00:00 2001 From: Luthaf Date: Fri, 23 May 2014 19:11:15 +0100 Subject: [PATCH] Correction d'un bug dans l'interaction avec songbook-web MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Les chaines etait passées comme des instances de str, et les carnets produits étaient vides. --- songbook_core/build.py | 13 +++++++++---- songbook_core/errors.py | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/songbook_core/build.py b/songbook_core/build.py index a471f07e..6a4a91d4 100644 --- a/songbook_core/build.py +++ b/songbook_core/build.py @@ -114,10 +114,15 @@ class Songbook(object): content = self.config["content"] self.config["content"] = [] for elem in content: - if isinstance(elem, unicode): + if isinstance(elem, str) or isinstance(elem, unicode): self.config["content"].append(("song", elem)) - else: + elif isinstance(elem, list): self.config["content"].append((elem[0], elem[1])) + else: + raise errors.SBFileError( + "Syntax error: could not decode the content " + "of {0}".format(self.basename) + ) # Ensure self.config['authwords'] contains all entries for (key, value) in DEFAULT_AUTHWORDS.items(): @@ -126,7 +131,7 @@ class Songbook(object): def _parse_songs(self): """Parse content included in songbook.""" - self.contentlist = SongbookContent(self.config['datadir']) + self.contentlist = SongbookContent(self.config['datadir']) self.contentlist.append_list(self.config['content']) def write_tex(self, output): @@ -149,7 +154,7 @@ class Songbook(object): context['filename'] = output.name[:-4] self._set_songs_default(context) - + print(self.contentlist.content) renderer.render_tex(output, context) diff --git a/songbook_core/errors.py b/songbook_core/errors.py index 6b850712..d724ae14 100644 --- a/songbook_core/errors.py +++ b/songbook_core/errors.py @@ -10,6 +10,19 @@ class SongbookError(Exception): """ pass +class SBFileError(SongbookError): + """Error during songbook file decoding""" + + def __init__(self, message=None): + super(SBFileError, self).__init__() + self.message = message + + def __str__(self): + if self.message is None: + return str(self.original) + else: + return self.message + class TemplateError(SongbookError): """Error during template generation"""