From 284706f76b54fa18b194208cf8795c6ec3bd6424 Mon Sep 17 00:00:00 2001 From: Oliverpool Date: Fri, 22 Jul 2016 11:56:52 +0200 Subject: [PATCH] include relative to yaml file if not found in datadirs --- patacrep/content/include.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/patacrep/content/include.py b/patacrep/content/include.py index 5dca3940..b340e194 100644 --- a/patacrep/content/include.py +++ b/patacrep/content/include.py @@ -14,15 +14,21 @@ from patacrep import encoding, errors LOGGER = logging.getLogger(__name__) -def load_from_datadirs(filename, songdirs): - """Load 'filename' from one of the songdirs. +def load_from_datadirs(filename, songdirs, songbookfile_dir=None): + """Load 'filename', relative to: + - or one of the songdirs + - the dir of the songbook file dir - Raise an exception if it was not found in any songdir. + Raise an exception if it was not found in any directory. """ for path in songdirs: fullpath = os.path.join(path.fullpath, filename) if os.path.exists(fullpath): return fullpath + if songbookfile_dir: + fullpath = os.path.join(songbookfile_dir, filename) + if os.path.exists(fullpath): + return fullpath # File not found raise ContentError( "include", @@ -52,9 +58,13 @@ def parse(keyword, config, argument): if isinstance(argument, str): argument = [argument] - for path in argument: + for filename in argument: try: - filepath = load_from_datadirs(path, config['_songdir']) + filepath = load_from_datadirs( + filename, + config['_songdir'], + config.get('_songbookfile_dir') + ) except ContentError as error: new_contentlist.append_error(error) continue