From b7db9bcb6df6f8317729052da6a1ec883263829c Mon Sep 17 00:00:00 2001 From: Louis Date: Sat, 14 Jun 2014 15:54:21 +0200 Subject: [PATCH] [WIP] Managing titleprefixwords --- songbook_core/build.py | 18 ++++-------------- songbook_core/content/song.py | 2 +- songbook_core/songs.py | 6 ++---- 3 files changed, 7 insertions(+), 19 deletions(-) diff --git a/songbook_core/build.py b/songbook_core/build.py index cbef29a6..264d1e16 100755 --- a/songbook_core/build.py +++ b/songbook_core/build.py @@ -57,24 +57,15 @@ class Songbook(object): 'lang': 'english', 'sort': [u"by", u"album", u"@title"], 'content': None, + 'titleprefixwords': [], } self._parse_raw(raw_songbook) - @staticmethod - def _set_songs_default(config): - """Set the default values for the Song() class. - Argument: - - config : a dictionary containing the configuration - TODO Move this function elsewhere - """ - return - Song.sort = config['sort'] - if 'titleprefixwords' in config: - Song.prefixes = config['titleprefixwords'] - else: - Song.prefixes = [] + + + def __TODO(self): Song.authwords['after'] = [ re.compile(r"^.*%s\b(.*)" % after) for after @@ -142,7 +133,6 @@ class Songbook(object): context['content'] = self.contentlist context['filename'] = output.name[:-4] - self._set_songs_default(context) renderer.render_tex(output, context) diff --git a/songbook_core/content/song.py b/songbook_core/content/song.py index b2548933..27aca0e8 100644 --- a/songbook_core/content/song.py +++ b/songbook_core/content/song.py @@ -54,7 +54,7 @@ def parse(keyword, config, *arguments): for songdir in [os.path.join(d, 'songs') for d in config['datadir']]: for filename in glob.iglob(os.path.join(songdir, elem)): LOGGER.debug('Parsing file "{}"…'.format(filename)) - song = SongRenderer(filename) + song = SongRenderer(filename, config) songlist.append(song) config["languages"].update(song.languages) if len(songlist) > before: diff --git a/songbook_core/songs.py b/songbook_core/songs.py index 5e280413..27e59194 100644 --- a/songbook_core/songs.py +++ b/songbook_core/songs.py @@ -16,12 +16,10 @@ class Song(object): #: Ordre de tri sort = [] - #: Préfixes à ignorer pour le tri par titres - prefixes = [] #: Dictionnaire des options pour le traitement des auteurs authwords = {"after": [], "ignore": [], "sep": []} - def __init__(self, filename): + def __init__(self, filename, config): # Data extraction from the song with plastex data = parsetex(filename) self.titles = data['titles'] @@ -29,7 +27,7 @@ class Song(object): locale.strxfrm( unprefixed_title( unidecode(unicode(title, "utf-8")), - self.prefixes + config['titleprefixwords'] ) ) for title