diff --git a/patacrep/content/addpath.py b/patacrep/content/addpath.py new file mode 100755 index 00000000..88414d09 --- /dev/null +++ b/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} diff --git a/patacrep/content/cd.py b/patacrep/content/cd.py index fd19434a..5125a448 100755 --- a/patacrep/content/cd.py +++ b/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,38 +9,25 @@ 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']] + config['_songdir'] = [path.clone().join(subpath) for path in config['_songdir']] processed_content = process_content(argument.get('content'), config) config['_songdir'] = old_songdir diff --git a/test/test_content/sort.source b/test/test_content/sort.source index 00c1d6e8..707efd08 100644 --- a/test/test_content/sort.source +++ b/test/test_content/sort.source @@ -1,6 +1,5 @@ -- cd: +- addpath: path: "datadir_sort" - yaml_as_root: yes content: - section: name: "Title" diff --git a/test/test_songbook/content.yaml b/test/test_songbook/content.yaml index 0f1e4f89..15ce93fa 100644 --- a/test/test_songbook/content.yaml +++ b/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"