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 Example: When the following piece of content is met
sorted: sorted:
key: ["author", "@title"] key: ["author", "title"]
content: content:
- "a_song.sg" - "a_song.sg"
- "another_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: the parser associated to keyword 'sorted' get the arguments:
- keyword = "sorted" - keyword = "sorted"
- argument = { - argument = {
'key': ["author", "@title"], 'key': ["author", "title"],
'content': ["a_song.sg", "another_song.sg"], 'content': ["a_song.sg", "another_song.sg"],
} }
- config = <the config file of the current songbook>. - 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__) LOGGER = logging.getLogger(__name__)
DEFAULT_SORT = ['by', 'album', '@title'] DEFAULT_SORT = ['by', 'album', 'title']
def normalize_string(string): def normalize_string(string):
"""Return a normalized string. """Return a normalized string.
@ -45,9 +45,9 @@ def key_generator(sort):
song = songrenderer.song song = songrenderer.song
songkey = [] songkey = []
for key in sort: for key in sort:
if key == "@title": if key == "title":
field = song.unprefixed_titles field = song.unprefixed_titles
elif key == "@path": elif key == "path":
field = song.fullpath field = song.fullpath
elif key == "by": elif key == "by":
field = song.authors field = song.authors
@ -88,8 +88,8 @@ def parse(keyword, config, argument):
- keyword: the string 'sorted'; - keyword: the string 'sorted';
- config: the current songbook configuration dictionary; - config: the current songbook configuration dictionary;
- argument: a dict of: - argument: a dict of:
key: the list of the fields used to sort songs (e.g. "by", "album", "@title") key: the list of the fields used to sort songs (e.g. "by", "album", "title")
a minus mean reverse order: "-@title" a minus mean reverse order: "-title"
content: content to be sorted. If this content content: content to be sorted. If this content
contain something else than a song, an exception is raised. contain something else than a song, an exception is raised.
""" """

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

@ -1,5 +1,5 @@
- sorted: - sorted:
key: "@title" key: "title"
content: content:
- exsong.sg - exsong.sg
- chordpro.csg - 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 - section{Title}
- chordpro.csg - "@TEST_FOLDER@/datadir_sorted/path1_title1_author1.csg"
- subdir/chordpro.csg - "@TEST_FOLDER@/datadir_sorted/path1_title1_author2.csg"
- exsong.sg - "@TEST_FOLDER@/datadir_sorted/path2_title1_author1.csg"
- "@TEST_FOLDER@/datadir_sorted/path2_title1_author2.csg"
- exsong.sg - "@TEST_FOLDER@/datadir_sorted/path1_title2_author1.csg"
- texsong.tsg - "@TEST_FOLDER@/datadir_sorted/path1_title2_author2.csg"
- chordpro.csg - "@TEST_FOLDER@/datadir_sorted/path2_title2_author1.csg"
- subdir/chordpro.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: - cwd:
key: "@title" path: "datadir_sorted"
- sorted:
key: [by, "@title"]
content: content:
cwd: - section:
path: "./" 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 unittest
import yaml import yaml
from pkg_resources import resource_filename
from patacrep.songs import DataSubpath from patacrep.songs import DataSubpath
from patacrep import content, files from patacrep import content, files
from patacrep.content import song, section, songsection, tex 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): if not os.path.exists(controlname):
raise Exception("Missing control:" + str(sourcelist).replace("'", '"')) raise Exception("Missing control:" + str(sourcelist).replace("'", '"'))
with open(controlname, mode="r", encoding="utf8") as controlfile: 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) self.assertEqual(controllist, sourcelist)

Loading…
Cancel
Save