diff --git a/patacrep/content/__init__.py b/patacrep/content/__init__.py index ac7e962e..f9c78fd6 100755 --- a/patacrep/content/__init__.py +++ b/patacrep/content/__init__.py @@ -36,7 +36,7 @@ class), defined in this module (or of subclasses of this class). Example: When the following piece of content is met sorted: - key: ["author", "@title"] + key: ["author", "title"] content: - "a_song.sg" - "another_song.sg" @@ -44,7 +44,7 @@ Example: When the following piece of content is met the parser associated to keyword 'sorted' get the arguments: - keyword = "sorted" - argument = { - 'key': ["author", "@title"], + 'key': ["author", "title"], 'content': ["a_song.sg", "another_song.sg"], } - config = . diff --git a/patacrep/content/sorted.py b/patacrep/content/sorted.py index 2bd4cc34..452a0c04 100755 --- a/patacrep/content/sorted.py +++ b/patacrep/content/sorted.py @@ -14,7 +14,7 @@ from patacrep.content.song import OnlySongsError LOGGER = logging.getLogger(__name__) -DEFAULT_SORT = ['by', 'album', '@title'] +DEFAULT_SORT = ['by', 'album', 'title'] def normalize_string(string): """Return a normalized string. @@ -45,9 +45,9 @@ def key_generator(sort): song = songrenderer.song songkey = [] for key in sort: - if key == "@title": + if key == "title": field = song.unprefixed_titles - elif key == "@path": + elif key == "path": field = song.fullpath elif key == "by": field = song.authors @@ -88,8 +88,8 @@ def parse(keyword, config, argument): - keyword: the string 'sorted'; - config: the current songbook configuration dictionary; - 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" + 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. """ diff --git a/test/test_content/datadir/songs/custom_list.yaml b/test/test_content/datadir/songs/custom_list.yaml index e32ff5c8..5a5cd657 100644 --- a/test/test_content/datadir/songs/custom_list.yaml +++ b/test/test_content/datadir/songs/custom_list.yaml @@ -1,6 +1,6 @@ - sorted: - key: "@title" + key: "title" content: - exsong.sg - chordpro.csg - - subdir/chordpro.csg \ No newline at end of file + - subdir/chordpro.csg diff --git a/test/test_content/datadir_sorted/path1_title1_author1.csg b/test/test_content/datadir_sorted/path1_title1_author1.csg new file mode 100644 index 00000000..f5dd92fc --- /dev/null +++ b/test/test_content/datadir_sorted/path1_title1_author1.csg @@ -0,0 +1,5 @@ +{title: Title1} +{artist: Author1} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path1_title1_author2.csg b/test/test_content/datadir_sorted/path1_title1_author2.csg new file mode 100644 index 00000000..13d6ecac --- /dev/null +++ b/test/test_content/datadir_sorted/path1_title1_author2.csg @@ -0,0 +1,5 @@ +{title: Title1} +{artist: Author2} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path1_title2_author1.csg b/test/test_content/datadir_sorted/path1_title2_author1.csg new file mode 100644 index 00000000..35e93160 --- /dev/null +++ b/test/test_content/datadir_sorted/path1_title2_author1.csg @@ -0,0 +1,5 @@ +{title: Title2} +{artist: Author1} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path1_title2_author2.csg b/test/test_content/datadir_sorted/path1_title2_author2.csg new file mode 100644 index 00000000..f2db9337 --- /dev/null +++ b/test/test_content/datadir_sorted/path1_title2_author2.csg @@ -0,0 +1,5 @@ +{title: Title2} +{artist: Author2} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path2_title1_author1.csg b/test/test_content/datadir_sorted/path2_title1_author1.csg new file mode 100644 index 00000000..f5dd92fc --- /dev/null +++ b/test/test_content/datadir_sorted/path2_title1_author1.csg @@ -0,0 +1,5 @@ +{title: Title1} +{artist: Author1} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path2_title1_author2.csg b/test/test_content/datadir_sorted/path2_title1_author2.csg new file mode 100644 index 00000000..13d6ecac --- /dev/null +++ b/test/test_content/datadir_sorted/path2_title1_author2.csg @@ -0,0 +1,5 @@ +{title: Title1} +{artist: Author2} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path2_title2_author1.csg b/test/test_content/datadir_sorted/path2_title2_author1.csg new file mode 100644 index 00000000..35e93160 --- /dev/null +++ b/test/test_content/datadir_sorted/path2_title2_author1.csg @@ -0,0 +1,5 @@ +{title: Title2} +{artist: Author1} + +Foo bar + diff --git a/test/test_content/datadir_sorted/path2_title2_author2.csg b/test/test_content/datadir_sorted/path2_title2_author2.csg new file mode 100644 index 00000000..f2db9337 --- /dev/null +++ b/test/test_content/datadir_sorted/path2_title2_author2.csg @@ -0,0 +1,5 @@ +{title: Title2} +{artist: Author2} + +Foo bar + diff --git a/test/test_content/sorted.control b/test/test_content/sorted.control index 5bbdd48d..76558cf9 100644 --- a/test/test_content/sorted.control +++ b/test/test_content/sorted.control @@ -1,9 +1,27 @@ -- texsong.tsg -- chordpro.csg -- subdir/chordpro.csg -- exsong.sg - -- exsong.sg -- texsong.tsg -- chordpro.csg -- subdir/chordpro.csg \ No newline at end of file +- section{Title} +- "@TEST_FOLDER@/datadir_sorted/path1_title1_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title1_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title1_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title1_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title2_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title2_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title2_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title2_author2.csg" +- section{Author, Title} +- "@TEST_FOLDER@/datadir_sorted/path1_title1_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title1_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title2_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title2_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title1_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title1_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title2_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title2_author2.csg" +- section{Path, Title} +- "@TEST_FOLDER@/datadir_sorted/path1_title1_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title1_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title2_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path1_title2_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title1_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title1_author2.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title2_author1.csg" +- "@TEST_FOLDER@/datadir_sorted/path2_title2_author2.csg" diff --git a/test/test_content/sorted.source b/test/test_content/sorted.source index ef51ebb6..b3fedbab 100644 --- a/test/test_content/sorted.source +++ b/test/test_content/sorted.source @@ -1,7 +1,15 @@ -- sorted: - key: "@title" -- sorted: - key: [by, "@title"] +- cwd: + path: "datadir_sorted" content: - cwd: - path: "./" + - section: + name: "Title" + - sorted: + key: title + - section: + name: "Author, Title" + - sorted: + key: [by, title] + - section: + name: "Path, Title" + - sorted: + key: [path, title] diff --git a/test/test_content/test_content.py b/test/test_content/test_content.py index 590dde91..060467d9 100644 --- a/test/test_content/test_content.py +++ b/test/test_content/test_content.py @@ -7,6 +7,8 @@ import os import unittest import yaml +from pkg_resources import resource_filename + from patacrep.songs import DataSubpath from patacrep import content, files from patacrep.content import song, section, songsection, tex @@ -63,7 +65,10 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest): if not os.path.exists(controlname): raise Exception("Missing control:" + str(sourcelist).replace("'", '"')) with open(controlname, mode="r", encoding="utf8") as controlfile: - controllist = yaml.load(controlfile) + controllist = [ + elem.replace("@TEST_FOLDER@", files.path2posix(resource_filename(__name__, ""))) + for elem in yaml.load(controlfile) + ] self.assertEqual(controllist, sourcelist)