Browse Source

Songdir usage more coherent

pull/207/head
Oliverpool 9 years ago
parent
commit
0a6164792b
  1. 13
      patacrep/content/cd.py
  2. 17
      patacrep/content/include.py
  3. 1
      patacrep/content/tex.py
  4. 3
      test/test_content/sort.source
  5. 3
      test/test_songbook/content.yaml

13
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,18 +20,26 @@ 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']
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)

17
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

1
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:

3
test/test_content/sort.source

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

3
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"

Loading…
Cancel
Save