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

3
test/test_content/sort.source

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

3
test/test_songbook/content.yaml

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

Loading…
Cancel
Save