Browse Source

sorted is now in yaml

pull/190/head
Oliverpool 9 years ago
parent
commit
3f02240670
  1. 24
      patacrep/content/sorted.py
  2. 5
      test/test_content/sorted.control
  3. 5
      test/test_content/sorted.source
  4. 2
      test/test_songbook/content.sb

24
patacrep/content/sorted.py

@ -67,23 +67,25 @@ def key_generator(sort):
return ordered_song_keys return ordered_song_keys
#pylint: disable=unused-argument #pylint: disable=unused-argument
def parse(keyword, config, argument, contentlist): def parse(keyword, config, argument):
"""Return a sorted list of songs contained in 'contentlist'. """Return a sorted list of songs.
Arguments: Arguments:
- keyword: the string 'sorted'; - keyword: the string 'sorted';
- config: the current songbook configuration dictionary; - config: the current songbook configuration dictionary;
- argument: the list of the fields used to sort songs, as strings - argument: a dict of:
separated by commas (e.g. "by, album, @title"); key: the list of the fields used to sort songs (e.g. "by", "album", "@title")
- contentlist: the list of content to be sorted. If this content a minus mean reverse order: "-@title"
contain something else than a song, an exception is raised. content: content to be sorted. If this content
contain something else than a song, an exception is raised.
""" """
if argument: if argument is None:
sort = [key.strip() for key in argument.split(",")] argument = {}
else: sort = argument.get('key', DEFAULT_SORT)
sort = DEFAULT_SORT if isinstance(sort, str):
sort = [sort]
try: try:
songlist = process_content(contentlist, config) songlist = process_content(argument.get('content'), config)
except OnlySongsError as error: except OnlySongsError as error:
return EmptyContentList(errors=[ContentError(keyword, ( return EmptyContentList(errors=[ContentError(keyword, (
"Content list of this keyword can be only songs (or content " "Content list of this keyword can be only songs (or content "

5
test/test_content/sorted.control

@ -1 +1,4 @@
["chordpro.csg", "exsong.sg", "subdir/chordpro.csg", "texsong.tsg"] [
"texsong.tsg", "chordpro.csg", "subdir/chordpro.csg", "exsong.sg",
"exsong.sg", "texsong.tsg", "chordpro.csg", "subdir/chordpro.csg"
]

5
test/test_content/sorted.source

@ -1 +1,4 @@
[["sorted(fullpath)"]] - sorted:
key: "@title"
- sorted:
key: [by, "@title"]

2
test/test_songbook/content.sb

@ -8,7 +8,7 @@ chords:
content: content:
- section: Test of section - section: Test of section
- ["sorted"] - sorted:
- songsection: Test of song section - songsection: Test of song section
- cwd: - cwd:
path: content_datadir/content path: content_datadir/content

Loading…
Cancel
Save