Browse Source

[WIP] Managing authwords

pull/47/head
Louis 11 years ago
parent
commit
b695e30395
  1. 33
      songbook_core/build.py
  2. 10
      songbook_core/data/templates/default.tex
  3. 5
      songbook_core/songs.py

33
songbook_core/build.py

@ -62,23 +62,6 @@ class Songbook(object):
self._parse_raw(raw_songbook) self._parse_raw(raw_songbook)
def __TODO(self):
Song.authwords['after'] = [
re.compile(r"^.*%s\b(.*)" % after)
for after
in config['authwords']["after"]
]
Song.authwords['ignore'] = config['authwords']['ignore']
Song.authwords['sep'] = [
re.compile(r"^(.*)%s (.*)$" % sep)
for sep in ([
" %s" % sep for sep in config['authwords']["sep"]
] + [','])
]
def _parse_raw(self, raw_songbook): def _parse_raw(self, raw_songbook):
"""Parse raw_songbook. """Parse raw_songbook.
@ -87,12 +70,26 @@ class Songbook(object):
""" """
self.config.update(raw_songbook) self.config.update(raw_songbook)
self._set_datadir() self._set_datadir()
self._set_authwords()
# TODO This should be moved elsewhere def _set_authwords(self):
# 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
# Convert strings to regular expressions
self.config["authwords"]['after'] = [
re.compile(r"^.*%s\b(.*)" % after)
for after
in self.config['authwords']["after"]
]
self.config["authwords"]['sep'] = [
re.compile(r"^(.*)%s (.*)$" % sep)
for sep in ([
" %s" % sep for sep in self.config['authwords']["sep"]
] + [','])
]
def _set_datadir(self): def _set_datadir(self):
"""Set the default values for datadir""" """Set the default values for datadir"""

10
songbook_core/data/templates/default.tex

@ -98,11 +98,11 @@
(* endfor*) (* endfor*)
(* for key in titleprefixkeys *) (* for key in titleprefixkeys *)
(* for word in authwords.key *) (* for word in authwords.key *)
(* if key=="after" *) (* if key=="after" *)
\authbyword{((word))} \authbyword{((word))}
(* else *) (* else *)
\auth((key))word{((word))} \auth((key))word{((word))}
(* endif *) (* endif *)
(* endfor *) (* endfor *)
(* endfor*) (* endfor*)

5
songbook_core/songs.py

@ -14,9 +14,6 @@ from songbook_core.plastex import parsetex
class Song(object): class Song(object):
"""Song management""" """Song management"""
#: Dictionnaire des options pour le traitement des auteurs
authwords = {"after": [], "ignore": [], "sep": []}
def __init__(self, filename, config): 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)
@ -38,7 +35,7 @@ class Song(object):
self.normalized_authors = [ self.normalized_authors = [
locale.strxfrm(author) locale.strxfrm(author)
for author for author
in processauthors(self.args["by"], **self.authwords) in processauthors(self.args["by"], **config["authwords"])
] ]
else: else:
self.normalized_authors = [] self.normalized_authors = []

Loading…
Cancel
Save