Browse Source

Songdir usage more coherent

pull/207/head
Oliverpool 9 years ago
parent
commit
0a6164792b
  1. 15
      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

15
patacrep/content/cd.py

@ -10,6 +10,7 @@ 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 songs, whith a different base path.
@ -19,19 +20,27 @@ def parse(keyword, config, argument):
- 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 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 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 This function adds 'path' to the directories where songs are searched
for, and then processes the content. for, and then processes the content.
The 'path' is added as a relative path to every path already present in If 'yaml_as_root' is not set the 'path' is added as a relative path to
config['songdir'] (which are 'songs' dir inside the datadirs). 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'] subpath = argument['path']
old_songdir = config['_songdir'] 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) processed_content = process_content(argument.get('content'), config)
config['_songdir'] = old_songdir config['_songdir'] = old_songdir

17
patacrep/content/include.py

@ -14,18 +14,19 @@ from patacrep import encoding, errors, files
LOGGER = logging.getLogger(__name__) LOGGER = logging.getLogger(__name__)
def load_from_datadirs(path, datadirs): def load_from_datadirs(filename, songdirs):
"""Load 'path' from one of the datadirs. """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): for path in songdirs:
if os.path.exists(filepath): fullpath = os.path.join(path.fullpath, filename)
return filepath if os.path.exists(fullpath):
return fullpath
# File not found # File not found
raise ContentError( raise ContentError(
"include", "include",
errors.notfound(path, list(files.iter_datadirs(datadirs))) errors.notfound(filename, list(songdirs))
) )
#pylint: disable=unused-argument #pylint: disable=unused-argument
@ -53,7 +54,7 @@ def parse(keyword, config, argument):
for path in argument: for path in argument:
try: try:
filepath = load_from_datadirs(path, config['_datadir']) filepath = load_from_datadirs(path, config['_songdir'])
except ContentError as error: except ContentError as error:
new_contentlist.append_error(error) new_contentlist.append_error(error)
continue continue

1
patacrep/content/tex.py

@ -45,7 +45,6 @@ def parse(keyword, argument, config):
filelist = ContentList() filelist = ContentList()
basefolders = itertools.chain( basefolders = itertools.chain(
(path.fullpath for path in config['_songdir']), (path.fullpath for path in config['_songdir']),
files.iter_datadirs(config['_datadir']),
files.iter_datadirs(config['_datadir'], 'latex'), files.iter_datadirs(config['_datadir'], 'latex'),
) )
for filename in argument: for filename in argument:

3
test/test_content/sort.source

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

3
test/test_songbook/content.yaml

@ -13,7 +13,8 @@ content:
- songsection: Test of song section - songsection: Test of song section
- cd: - cd:
# 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