Browse Source

[WIP] Managing titleprefixwords

pull/47/head
Louis 11 years ago
parent
commit
b7db9bcb6d
  1. 18
      songbook_core/build.py
  2. 2
      songbook_core/content/song.py
  3. 6
      songbook_core/songs.py

18
songbook_core/build.py

@ -57,24 +57,15 @@ class Songbook(object):
'lang': 'english', 'lang': 'english',
'sort': [u"by", u"album", u"@title"], 'sort': [u"by", u"album", u"@title"],
'content': None, 'content': None,
'titleprefixwords': [],
} }
self._parse_raw(raw_songbook) 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 def __TODO(self):
Song.sort = config['sort']
if 'titleprefixwords' in config:
Song.prefixes = config['titleprefixwords']
else:
Song.prefixes = []
Song.authwords['after'] = [ Song.authwords['after'] = [
re.compile(r"^.*%s\b(.*)" % after) re.compile(r"^.*%s\b(.*)" % after)
for after for after
@ -142,7 +133,6 @@ class Songbook(object):
context['content'] = self.contentlist context['content'] = self.contentlist
context['filename'] = output.name[:-4] context['filename'] = output.name[:-4]
self._set_songs_default(context)
renderer.render_tex(output, context) renderer.render_tex(output, context)

2
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 songdir in [os.path.join(d, 'songs') for d in config['datadir']]:
for filename in glob.iglob(os.path.join(songdir, elem)): for filename in glob.iglob(os.path.join(songdir, elem)):
LOGGER.debug('Parsing file "{}"'.format(filename)) LOGGER.debug('Parsing file "{}"'.format(filename))
song = SongRenderer(filename) song = SongRenderer(filename, config)
songlist.append(song) songlist.append(song)
config["languages"].update(song.languages) config["languages"].update(song.languages)
if len(songlist) > before: if len(songlist) > before:

6
songbook_core/songs.py

@ -16,12 +16,10 @@ class Song(object):
#: Ordre de tri #: Ordre de tri
sort = [] sort = []
#: Préfixes à ignorer pour le tri par titres
prefixes = []
#: Dictionnaire des options pour le traitement des auteurs #: Dictionnaire des options pour le traitement des auteurs
authwords = {"after": [], "ignore": [], "sep": []} authwords = {"after": [], "ignore": [], "sep": []}
def __init__(self, filename): def __init__(self, filename, config):
# Data extraction from the song with plastex # Data extraction from the song with plastex
data = parsetex(filename) data = parsetex(filename)
self.titles = data['titles'] self.titles = data['titles']
@ -29,7 +27,7 @@ class Song(object):
locale.strxfrm( locale.strxfrm(
unprefixed_title( unprefixed_title(
unidecode(unicode(title, "utf-8")), unidecode(unicode(title, "utf-8")),
self.prefixes config['titleprefixwords']
) )
) )
for title for title

Loading…
Cancel
Save