From 3f02240670e503bbd4b0741050bc61fcef5937dd Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Tue, 12 Jan 2016 13:52:08 +0100 Subject: [PATCH] sorted is now in yaml --- patacrep/content/sorted.py | 24 +++++++++++++----------- test/test_content/sorted.control | 5 ++++- test/test_content/sorted.source | 5 ++++- test/test_songbook/content.sb | 2 +- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/patacrep/content/sorted.py b/patacrep/content/sorted.py index c14cc732..cd2fee1b 100755 --- a/patacrep/content/sorted.py +++ b/patacrep/content/sorted.py @@ -67,23 +67,25 @@ def key_generator(sort): return ordered_song_keys #pylint: disable=unused-argument -def parse(keyword, config, argument, contentlist): - """Return a sorted list of songs contained in 'contentlist'. +def parse(keyword, config, argument): + """Return a sorted list of songs. Arguments: - keyword: the string 'sorted'; - config: the current songbook configuration dictionary; - - argument: the list of the fields used to sort songs, as strings - separated by commas (e.g. "by, album, @title"); - - contentlist: the list of content to be sorted. If this content - contain something else than a song, an exception is raised. + - argument: a dict of: + key: the list of the fields used to sort songs (e.g. "by", "album", "@title") + a minus mean reverse order: "-@title" + content: content to be sorted. If this content + contain something else than a song, an exception is raised. """ - if argument: - sort = [key.strip() for key in argument.split(",")] - else: - sort = DEFAULT_SORT + if argument is None: + argument = {} + sort = argument.get('key', DEFAULT_SORT) + if isinstance(sort, str): + sort = [sort] try: - songlist = process_content(contentlist, config) + songlist = process_content(argument.get('content'), config) except OnlySongsError as error: return EmptyContentList(errors=[ContentError(keyword, ( "Content list of this keyword can be only songs (or content " diff --git a/test/test_content/sorted.control b/test/test_content/sorted.control index 5cfaa29d..ba02acf4 100644 --- a/test/test_content/sorted.control +++ b/test/test_content/sorted.control @@ -1 +1,4 @@ -["chordpro.csg", "exsong.sg", "subdir/chordpro.csg", "texsong.tsg"] \ No newline at end of file +[ +"texsong.tsg", "chordpro.csg", "subdir/chordpro.csg", "exsong.sg", +"exsong.sg", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg" +] \ No newline at end of file diff --git a/test/test_content/sorted.source b/test/test_content/sorted.source index 5b2bbf3a..f9806058 100644 --- a/test/test_content/sorted.source +++ b/test/test_content/sorted.source @@ -1 +1,4 @@ -[["sorted(fullpath)"]] \ No newline at end of file +- sorted: + key: "@title" +- sorted: + key: [by, "@title"] \ No newline at end of file diff --git a/test/test_songbook/content.sb b/test/test_songbook/content.sb index 5ff0bcca..997c5c0a 100644 --- a/test/test_songbook/content.sb +++ b/test/test_songbook/content.sb @@ -8,7 +8,7 @@ chords: content: - section: Test of section - - ["sorted"] + - sorted: - songsection: Test of song section - cwd: path: content_datadir/content