Browse Source

Rename datadir key to _datadir

pull/184/head
Oliverpool 9 years ago
parent
commit
fab3d4f128
  1. 26
      patacrep/build.py
  2. 2
      patacrep/content/include.py
  3. 4
      patacrep/content/tex.py
  4. 4
      patacrep/data/templates/default_songbook.sb.yml
  5. 64
      patacrep/data/templates/songbook_schema.yml
  6. 3
      patacrep/songbook/__main__.py
  7. 19
      patacrep/songs/__init__.py
  8. 1
      patacrep/songs/convert/__main__.py
  9. 1
      patacrep/utils.py

26
patacrep/build.py

@ -51,14 +51,8 @@ class Songbook(object):
def _set_datadir(self):
"""Set the default values for datadir"""
try:
if isinstance(self.config['datadir'], str):
self.config['datadir'] = [self.config['datadir']]
except KeyError: # No datadir in the raw_songbook
self.config['datadir'] = [os.path.abspath('.')]
abs_datadir = []
for path in self.config['datadir']:
for path in self.config['_datadir']:
if os.path.exists(path) and os.path.isdir(path):
abs_datadir.append(os.path.abspath(path))
else:
@ -66,10 +60,10 @@ class Songbook(object):
"Ignoring non-existent datadir '{}'.".format(path)
)
self.config['datadir'] = abs_datadir
self.config['_datadir'] = abs_datadir
self.config['_songdir'] = [
DataSubpath(path, 'songs')
for path in self.config['datadir']
for path in self.config['_datadir']
]
def write_tex(self, output):
@ -82,26 +76,26 @@ class Songbook(object):
config = DEFAULT_CONFIG.copy()
config.update(self.config)
renderer = TexBookRenderer(
config['template'],
config['datadir'],
config['lang'],
config['encoding'],
config['book']['template'],
config['_datadir'],
config['book']['lang'],
config['book']['encoding'],
)
config.update(renderer.get_variables())
config.update(self.config)
config['_compiled_authwords'] = authors.compile_authwords(
copy.deepcopy(config['authwords'])
copy.deepcopy(config['authors'])
)
# Loading custom plugins
config['_content_plugins'] = files.load_plugins(
datadirs=config.get('datadir', []),
datadirs=config['_datadir'],
root_modules=['content'],
keyword='CONTENT_PLUGINS',
)
config['_song_plugins'] = files.load_plugins(
datadirs=config.get('datadir', []),
datadirs=config['_datadir'],
root_modules=['songs'],
keyword='SONG_RENDERERS',
)['tsg']

2
patacrep/content/include.py

@ -41,7 +41,7 @@ def parse(keyword, config, argument, contentlist):
new_contentlist = []
for path in contentlist:
filepath = load_from_datadirs(path, config.get('datadir', []))
filepath = load_from_datadirs(path, config['_datadir'])
content_file = None
try:
with encoding.open_read(

4
patacrep/content/tex.py

@ -38,8 +38,8 @@ def parse(keyword, argument, contentlist, config):
filelist = []
basefolders = itertools.chain(
(path.fullpath for path in config['_songdir']),
files.iter_datadirs(config['datadir']),
files.iter_datadirs(config['datadir'], 'latex'),
files.iter_datadirs(config['_datadir']),
files.iter_datadirs(config['_datadir'], 'latex'),
)
for filename in contentlist:
checked_file = None

4
patacrep/data/templates/default_songbook.sb.yml

@ -2,6 +2,7 @@ book:
lang: en
encoding: utf-8
pictures: yes
template: default.tex
chords: # Options relatives aux accords
show: yes
@ -28,8 +29,7 @@ titles: # Comment sont analysés les titres
- To
- Do
template: # Des choses spécifiques au template
file: STRING
#template: # Des choses spécifiques au template
# latex: # Des choses spécifiques au LaTeX
# classoptions: STRING

64
patacrep/data/templates/songbook_schema.yml

@ -2,15 +2,17 @@ type: //rec
optional:
content: //str
required:
_cache: //bool
_datadir:
type: //arr
contents: //str
book:
type: //rec
required:
encoding: //str
lang: //str
pictures: //bool
datadir:
type: //arr
contents: //str
template: //str
chords:
type: //rec
required:
@ -73,31 +75,31 @@ required:
- type: //arr
contents: //str
- type: //nil
template:
_description: "Des choses spécifiques au template"
type: //rec
required:
file: //str
optional:
latex:
type: //rec
required:
classoptions: //str
color:
type: //rec
required:
songnumber: //str
notebg: //str
indexbg: //str
titlepage:
type: //rec
required:
title: //str
author: //str
subtitle: //str
version: //str
url: //str
email: //str
picture: //str
picturecopyright: //str
footer: //str
# template:
# _description: "Des choses spécifiques au template"
# type: //rec
# required:
# file: //str
# optional:
# latex:
# type: //rec
# required:
# classoptions: //str
# color:
# type: //rec
# required:
# songnumber: //str
# notebg: //str
# indexbg: //str
# titlepage:
# type: //rec
# required:
# title: //str
# author: //str
# subtitle: //str
# version: //str
# url: //str
# email: //str
# picture: //str
# picturecopyright: //str
# footer: //str

3
patacrep/songbook/__main__.py

@ -175,7 +175,8 @@ def main():
# Default value
datadirs.append(os.path.dirname(os.path.abspath(songbook_path)))
songbook['book']['datadir'] = datadirs
del songbook['book']['datadir']
songbook['_datadir'] = datadirs
songbook['_cache'] = options.cache[0]
try:

19
patacrep/songs/__init__.py

@ -12,14 +12,7 @@ from patacrep.authors import process_listauthors
LOGGER = logging.getLogger(__name__)
DEFAULT_CONFIG = {
'template': "default.tex",
'lang': 'en',
'content': [],
'titleprefixwords': [],
'encoding': None,
'datadir': [],
}
DEFAULT_CONFIG = {}
def cached_name(datadir, filename):
"""Return the filename of the cache version of the file."""
@ -117,8 +110,8 @@ class Song:
self.fullpath = os.path.join(self.datadir, subpath)
self.subpath = subpath
self._filehash = None
self.encoding = config["encoding"]
self.default_lang = config["lang"]
self.encoding = config['book']["encoding"]
self.default_lang = config['book']["lang"]
self.config = config
if self._cache_retrieved():
@ -135,7 +128,7 @@ class Song:
self.unprefixed_titles = [
unprefixed_title(
title,
config['titleprefixwords']
config['titles']['prefix']
)
for title
in self.titles
@ -221,7 +214,7 @@ class Song:
def iter_datadirs(self, *subpath):
"""Return an iterator of existing datadirs (with an optionnal subpath)
"""
yield from files.iter_datadirs(self.config['datadir'], *subpath)
yield from files.iter_datadirs(self.config['_datadir'], *subpath)
def search_datadir_file(self, filename, extensions=None, directories=None):
"""Search for a file name.
@ -249,7 +242,7 @@ class Song:
if extensions is None:
extensions = ['']
if directories is None:
directories = self.config['datadir']
directories = self.config['_datadir']
songdir = os.path.dirname(self.fullpath)
for extension in extensions:

1
patacrep/songs/convert/__main__.py

@ -33,6 +33,7 @@ if __name__ == "__main__":
dest = sys.argv[2]
song_files = sys.argv[3:]
# todo : what is the datadir argument used for?
renderers = files.load_plugins(
datadirs=DEFAULT_CONFIG.get('datadir', []),
root_modules=['songs'],

1
patacrep/utils.py

@ -102,7 +102,6 @@ def validate_config_schema(config):
"""
data = config.copy()
data = remove_keys(data, ['_cache'])
rx_checker = Rx.Factory({"register_core_types": True})
schema_path = pkg_datapath('templates', 'songbook_schema.yml')

Loading…
Cancel
Save