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.""" """Change base directory before importing songs."""
import os
from patacrep.content import process_content, validate_parser_argument from patacrep.content import process_content, validate_parser_argument
from patacrep.songs import DataSubpath from patacrep.songs import DataSubpath
@ -26,14 +28,16 @@ def parse(keyword, config, argument):
for, and then processes the content. for, and then processes the content.
The 'path' is added: 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 - then as a relative path to every path already present in
config['songdir']. config['songdir'].
""" """
subpath = argument['path'] subpath = argument['path']
old_songdir = config['_songdir'] old_songdir = config['_songdir']
sbdir = os.path.dirname(config['_filepath'])
config['_songdir'] = ( config['_songdir'] = (
[DataSubpath(".", subpath)] + [DataSubpath(sbdir, subpath)] +
[path.clone().join(subpath) for path in 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)

1
patacrep/data/templates/songbook_model.yml

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

10
patacrep/songbook/__main__.py

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

5
test/test_content/sorted.source

@ -1,4 +1,7 @@
- sorted: - sorted:
key: "@title" key: "@title"
- sorted: - 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: with open(sourcename, mode="r", encoding="utf8") as sourcefile:
sbcontent = yaml.load(sourcefile) sbcontent = yaml.load(sourcefile)
config = cls.config.copy()
config['_filepath'] = base
with logging_reduced('patacrep.content.song'): 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] sourcelist = [cls._clean_path(elem) for elem in expandedlist]
controlname = "{}.control".format(base) controlname = "{}.control".format(base)

5
test/test_songbook/content.sb

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