Browse Source

Split the cd plugin

pull/207/head
Oliverpool 9 years ago
parent
commit
f0ac98a5d8
  1. 40
      patacrep/content/addpath.py
  2. 22
      patacrep/content/cd.py
  3. 3
      test/test_content/sort.source
  4. 3
      test/test_songbook/content.yaml

40
patacrep/content/addpath.py

@ -0,0 +1,40 @@
"""Add a path directory to the 'songdir' list."""
from patacrep.content import process_content, validate_parser_argument
from patacrep.songs import DataSubpath
#pylint: disable=unused-argument
@validate_parser_argument("""
type: //rec
optional:
content: //any
required:
path: //str
""")
def parse(keyword, config, argument):
"""Return a list of songs, whith an another base path.
Arguments:
- keyword: unused;
- config: the current songbook configuration dictionary;
- argument: a dict containing:
path: string specifying the path to add to the songdirs list;
content: songbook content, that is parsed by
patacrep.content.process_content().
This function adds 'path' to the directories where songs are searched
for, and then processes the content.
The 'path' is added as a relative path to the dir of the songbook file.
"""
subpath = argument['path']
old_songdir = config['_songdir']
config['_songdir'] = [DataSubpath(config['_songbookfile_dir'], subpath)]
config['_songdir'].extend(old_songdir)
processed_content = process_content(argument.get('content'), config)
config['_songdir'] = old_songdir
return processed_content
CONTENT_PLUGINS = {'addpath': parse}

22
patacrep/content/cd.py

@ -1,7 +1,6 @@
"""Change base directory before importing songs."""
from patacrep.content import process_content, validate_parser_argument
from patacrep.songs import DataSubpath
#pylint: disable=unused-argument
@validate_parser_argument("""
@ -10,37 +9,24 @@ required:
path: //str
optional:
content: //any
yaml_as_root: //bool
""")
def parse(keyword, config, argument):
"""Return a list songs, whith a different base path.
"""Return a list of songs, whith a different base path.
Arguments:
- keyword: unused;
- config: the current songbook configuration dictionary;
- argument: a dict containing:
path: string specifying the path to use as root;
yaml_as_root: (optional) if the yaml file folder should
be used as root folder
path: string specifying the path to append to current songdirs;
content: songbook content, that is parsed by
patacrep.content.process_content().
This function adds 'path' to the directories where songs are searched
for, and then processes the content.
If 'yaml_as_root' is not set the 'path' is added as a relative path to
every path already present in config['songdir'] (which are 'songs' dir
inside the datadirs).
Otherwise only the 'path' folder of the yaml file is inserted as first
folder to the `songdir` list.
The 'path' is added as a relative path to every path already present
in config['songdir'] (which are 'songs' dir inside the datadirs).
"""
subpath = argument['path']
old_songdir = config['_songdir']
if argument.get('yaml_as_root', False):
config['_songdir'] = [DataSubpath(config['_songbookfile_dir'], subpath)]
config['_songdir'].extend(old_songdir)
else:
config['_songdir'] = [path.clone().join(subpath) for path in config['_songdir']]
processed_content = process_content(argument.get('content'), config)

3
test/test_content/sort.source

@ -1,6 +1,5 @@
- cd:
- addpath:
path: "datadir_sort"
yaml_as_root: yes
content:
- section:
name: "Title"

3
test/test_songbook/content.yaml

@ -11,10 +11,9 @@ content:
- section: Test of section
- sort:
- songsection: Test of song section
- cd:
- addpath:
# relative to yaml songfile
path: content_datadir/content
yaml_as_root: yes
content:
- "song.csg"
- "song.tsg"

Loading…
Cancel
Save