Browse Source

song is now in yaml

pull/190/head
Oliverpool 9 years ago
parent
commit
a2d2aea081
  1. 24
      patacrep/content/__init__.py
  2. 6
      patacrep/content/song.py

24
patacrep/content/__init__.py

@ -243,10 +243,11 @@ def process_content(content, config=None):
plugins = config.get('_content_plugins', {}) plugins = config.get('_content_plugins', {})
keyword_re = re.compile(r'^ *(?P<keyword>[\w\*]*) *(\((?P<argument>.*)\))? *$') keyword_re = re.compile(r'^ *(?P<keyword>[\w\*]*) *(\((?P<argument>.*)\))? *$')
if not content: if not content:
content = [["song"]] content = [ { 'song': None} ]
for elem in content: for elem in content:
if isinstance(elem, str):
elem = { 'song': [elem] }
if isinstance(elem, dict): if isinstance(elem, dict):
# new way
for keyword, argument in elem.items(): for keyword, argument in elem.items():
if keyword not in plugins: if keyword not in plugins:
contentlist.append_error(ContentError(keyword, "Unknown content type.")) contentlist.append_error(ContentError(keyword, "Unknown content type."))
@ -257,22 +258,5 @@ def process_content(content, config=None):
config=config, config=config,
)) ))
else: else:
# old way contentlist.append_error(ContentError(elem, "Unknown content type."))
if isinstance(elem, str):
elem = ["song", elem]
try:
match = keyword_re.match(elem[0]).groupdict()
except AttributeError:
contentlist.append_error(ContentError(elem[0], "Cannot parse content type."))
continue
(keyword, argument) = (match['keyword'], match['argument'])
if keyword not in plugins:
contentlist.append_error(ContentError(keyword, "Unknown content type."))
continue
contentlist.extend(plugins[keyword](
keyword,
argument=argument,
contentlist=elem[1:],
config=config,
))
return contentlist return contentlist

6
patacrep/content/song.py

@ -58,18 +58,18 @@ class SongRenderer(ContentItem):
return self.song.fullpath < other.song.fullpath return self.song.fullpath < other.song.fullpath
#pylint: disable=unused-argument #pylint: disable=unused-argument
def parse(keyword, argument, contentlist, config): def parse(keyword, argument, config):
"""Parse data associated with keyword 'song'. """Parse data associated with keyword 'song'.
Arguments: Arguments:
- keyword: unused; - keyword: unused;
- argument: unused; - argument: a list of strings, which are interpreted as regular
- contentlist: a list of strings, which are interpreted as regular
expressions (interpreted using the glob module), referring to songs. expressions (interpreted using the glob module), referring to songs.
- config: the current songbook configuration dictionary. - config: the current songbook configuration dictionary.
Return a list of Song() instances. Return a list of Song() instances.
""" """
contentlist = argument
plugins = config['_song_plugins'] plugins = config['_song_plugins']
if '_langs' not in config: if '_langs' not in config:
config['_langs'] = set() config['_langs'] = set()

Loading…
Cancel
Save