From a2d2aea0815d5f4da35af1db4b2d373ae751d67d Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Tue, 12 Jan 2016 14:10:49 +0100 Subject: [PATCH] song is now in yaml --- patacrep/content/__init__.py | 24 ++++-------------------- patacrep/content/song.py | 6 +++--- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index 43192a00..20ba1eba 100755 --- a/patacrep/content/__init__.py +++ b/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[\w\*]*) *(\((?P.*)\))? *$') 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 diff --git a/patacrep/content/song.py b/patacrep/content/song.py index 8e9519dc..869f87f6 100755 --- a/patacrep/content/song.py +++ b/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()