diff --git a/patacrep/content/cd.py b/patacrep/content/cd.py index 418a111f..2ef0fd10 100755 --- a/patacrep/content/cd.py +++ b/patacrep/content/cd.py @@ -10,6 +10,7 @@ required: path: //str optional: content: //any + yaml_as_root: //bool """) def parse(keyword, config, argument): """Return a list songs, whith a different base path. @@ -19,19 +20,27 @@ def parse(keyword, config, argument): - 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 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 every path already present 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 insert as first + folder to search into. """ subpath = argument['path'] old_songdir = config['_songdir'] - config['_songdir'] = [path.clone().join(subpath) for path in config['_songdir']] + if argument.get('yaml_as_root', False): + config['_songdir'].insert(0, DataSubpath(config['_songbookfile_dir'], subpath)) + else: + 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/patacrep/content/include.py b/patacrep/content/include.py index 0755c747..41d4b0ee 100644 --- a/patacrep/content/include.py +++ b/patacrep/content/include.py @@ -14,18 +14,19 @@ from patacrep import encoding, errors, files LOGGER = logging.getLogger(__name__) -def load_from_datadirs(path, datadirs): - """Load 'path' from one of the datadirs. +def load_from_datadirs(filename, songdirs): + """Load 'filename' from one of the songdirs. - Raise an exception if it was found if none of the datadirs of 'config'. + Raise an exception if it was not found in any songdir. """ - for filepath in files.iter_datadirs(datadirs, "songs", path): - if os.path.exists(filepath): - return filepath + for path in songdirs: + fullpath = os.path.join(path.fullpath, filename) + if os.path.exists(fullpath): + return fullpath # File not found raise ContentError( "include", - errors.notfound(path, list(files.iter_datadirs(datadirs))) + errors.notfound(filename, list(songdirs)) ) #pylint: disable=unused-argument @@ -53,7 +54,7 @@ def parse(keyword, config, argument): for path in argument: try: - filepath = load_from_datadirs(path, config['_datadir']) + filepath = load_from_datadirs(path, config['_songdir']) except ContentError as error: new_contentlist.append_error(error) continue diff --git a/patacrep/content/tex.py b/patacrep/content/tex.py index 406084a8..adf6950e 100755 --- a/patacrep/content/tex.py +++ b/patacrep/content/tex.py @@ -45,7 +45,6 @@ def parse(keyword, argument, config): filelist = ContentList() basefolders = itertools.chain( (path.fullpath for path in config['_songdir']), - files.iter_datadirs(config['_datadir']), files.iter_datadirs(config['_datadir'], 'latex'), ) for filename in argument: diff --git a/test/test_content/sort.source b/test/test_content/sort.source index 2a1b19af..00c1d6e8 100644 --- a/test/test_content/sort.source +++ b/test/test_content/sort.source @@ -1,5 +1,6 @@ - cd: - path: "../../datadir_sort" + 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 e4552f92..0f1e4f89 100644 --- a/test/test_songbook/content.yaml +++ b/test/test_songbook/content.yaml @@ -13,7 +13,8 @@ content: - songsection: Test of song section - cd: # relative to yaml songfile - path: /content_datadir/content + path: content_datadir/content + yaml_as_root: yes content: - "song.csg" - "song.tsg"