Browse Source

Rename '@title' and '@path' to 'title' and 'path'

pull/190/head
Louis 9 years ago
parent
commit
43fb4bd265
  1. 4
      patacrep/content/__init__.py
  2. 10
      patacrep/content/sorted.py
  3. 2
      test/test_content/datadir/songs/custom_list.yaml
  4. 5
      test/test_content/datadir_sorted/path1_title1_author1.csg
  5. 5
      test/test_content/datadir_sorted/path1_title1_author2.csg
  6. 5
      test/test_content/datadir_sorted/path1_title2_author1.csg
  7. 5
      test/test_content/datadir_sorted/path1_title2_author2.csg
  8. 5
      test/test_content/datadir_sorted/path2_title1_author1.csg
  9. 5
      test/test_content/datadir_sorted/path2_title1_author2.csg
  10. 5
      test/test_content/datadir_sorted/path2_title2_author1.csg
  11. 5
      test/test_content/datadir_sorted/path2_title2_author2.csg
  12. 36
      test/test_content/sorted.control
  13. 20
      test/test_content/sorted.source
  14. 7
      test/test_content/test_content.py

4
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 = <the config file of the current songbook>.

10
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.
"""

2
test/test_content/datadir/songs/custom_list.yaml

@ -1,5 +1,5 @@
- sorted:
key: "@title"
key: "title"
content:
- exsong.sg
- chordpro.csg

5
test/test_content/datadir_sorted/path1_title1_author1.csg

@ -0,0 +1,5 @@
{title: Title1}
{artist: Author1}
Foo bar

5
test/test_content/datadir_sorted/path1_title1_author2.csg

@ -0,0 +1,5 @@
{title: Title1}
{artist: Author2}
Foo bar

5
test/test_content/datadir_sorted/path1_title2_author1.csg

@ -0,0 +1,5 @@
{title: Title2}
{artist: Author1}
Foo bar

5
test/test_content/datadir_sorted/path1_title2_author2.csg

@ -0,0 +1,5 @@
{title: Title2}
{artist: Author2}
Foo bar

5
test/test_content/datadir_sorted/path2_title1_author1.csg

@ -0,0 +1,5 @@
{title: Title1}
{artist: Author1}
Foo bar

5
test/test_content/datadir_sorted/path2_title1_author2.csg

@ -0,0 +1,5 @@
{title: Title1}
{artist: Author2}
Foo bar

5
test/test_content/datadir_sorted/path2_title2_author1.csg

@ -0,0 +1,5 @@
{title: Title2}
{artist: Author1}
Foo bar

5
test/test_content/datadir_sorted/path2_title2_author2.csg

@ -0,0 +1,5 @@
{title: Title2}
{artist: Author2}
Foo bar

36
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
- 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"

20
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]

7
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)

Loading…
Cancel
Save