Browse Source

cwd can be relative to the songbook.sb file

pull/190/head
Oliverpool 9 years ago
parent
commit
e1fa1ef6f9
  1. 8
      patacrep/content/cwd.py
  2. 1
      patacrep/data/templates/songbook_model.yml
  3. 10
      patacrep/songbook/__main__.py
  4. 5
      test/test_content/sorted.source
  5. 4
      test/test_content/test_content.py
  6. 5
      test/test_songbook/content.sb

8
patacrep/content/cwd.py

@ -1,5 +1,7 @@
"""Change base directory before importing songs."""
import os
from patacrep.content import process_content, validate_parser_argument
from patacrep.songs import DataSubpath
@ -26,14 +28,16 @@ def parse(keyword, config, argument):
for, and then processes the content.
The 'path' is added:
- first as a relative path to the current directory;
- first as a relative path to the *.sb file directory;
- then as a relative path to every path already present in
config['songdir'].
"""
subpath = argument['path']
old_songdir = config['_songdir']
sbdir = os.path.dirname(config['_filepath'])
config['_songdir'] = (
[DataSubpath(".", subpath)] +
[DataSubpath(sbdir, subpath)] +
[path.clone().join(subpath) for path in config['_songdir']]
)
processed_content = process_content(argument.get('content'), config)

1
patacrep/data/templates/songbook_model.yml

@ -5,6 +5,7 @@ schema:
template: //any
required:
_cache: //bool
_filepath: //str
_datadir:
type: //arr
contents: //str

10
patacrep/songbook/__main__.py

@ -153,6 +153,9 @@ def main():
default_songbook.update(user_songbook)
songbook = dict(default_songbook)
songbook['_filepath'] = os.path.abspath(songbook_path)
sbdir = os.path.dirname(songbook['_filepath'])
# Gathering datadirs
datadirs = []
if options.datadir:
@ -162,16 +165,13 @@ def main():
if isinstance(songbook['book']['datadir'], str):
songbook['book']['datadir'] = [songbook['book']['datadir']]
datadirs += [
os.path.join(
os.path.dirname(os.path.abspath(songbook_path)),
path
)
os.path.join(sbdir, path)
for path in songbook['book']['datadir']
]
del songbook['book']['datadir']
# Default value
datadirs.append(os.path.dirname(os.path.abspath(songbook_path)))
datadirs.append(sbdir)
songbook['_datadir'] = datadirs
songbook['_cache'] = options.cache[0]

5
test/test_content/sorted.source

@ -1,4 +1,7 @@
- sorted:
key: "@title"
- sorted:
key: [by, "@title"]
key: [by, "@title"]
content:
cwd:
path: "./"

4
test/test_content/test_content.py

@ -53,8 +53,10 @@ class FileTest(unittest.TestCase, metaclass=dynamic.DynamicTest):
with open(sourcename, mode="r", encoding="utf8") as sourcefile:
sbcontent = yaml.load(sourcefile)
config = cls.config.copy()
config['_filepath'] = base
with logging_reduced('patacrep.content.song'):
expandedlist = content.process_content(sbcontent, cls.config.copy())
expandedlist = content.process_content(sbcontent, config)
sourcelist = [cls._clean_path(elem) for elem in expandedlist]
controlname = "{}.control".format(base)

5
test/test_songbook/content.sb

@ -11,9 +11,14 @@ content:
- sorted:
- songsection: Test of song section
- cwd:
# relative to sg file
path: content_datadir/content
content:
- "song.csg"
- "song.tsg"
- cwd:
# relative to datadir
path: ../content
content:
- tex: foo.tex
- include: include.sbc
Loading…
Cancel
Save