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', {})
keyword_re = re.compile(r'^ *(?P<keyword>[\w\*]*) *(\((?P<argument>.*)\))? *$')
if not content:
content = [["song"]]
content = [ { 'song': None} ]
for elem in content:
if isinstance(elem, str):
elem = { 'song': [elem] }
if isinstance(elem, dict):
# new way
for keyword, argument in elem.items():
if keyword not in plugins:
contentlist.append_error(ContentError(keyword, "Unknown content type."))
@ -257,22 +258,5 @@ def process_content(content, config=None):
config=config,
))
else:
# old way
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,
))
contentlist.append_error(ContentError(elem, "Unknown content type."))
return contentlist

6
patacrep/content/song.py

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

Loading…
Cancel
Save