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

2
patacrep/content/include.py

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

4
patacrep/content/tex.py

@ -38,8 +38,8 @@ def parse(keyword, argument, contentlist, config):
filelist = [] filelist = []
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']),
files.iter_datadirs(config['datadir'], 'latex'), files.iter_datadirs(config['_datadir'], 'latex'),
) )
for filename in contentlist: for filename in contentlist:
checked_file = None checked_file = None

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

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

64
patacrep/data/templates/songbook_schema.yml

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

3
patacrep/songbook/__main__.py

@ -175,7 +175,8 @@ def main():
# Default value # Default value
datadirs.append(os.path.dirname(os.path.abspath(songbook_path))) 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] songbook['_cache'] = options.cache[0]
try: try:

19
patacrep/songs/__init__.py

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

1
patacrep/songs/convert/__main__.py

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

1
patacrep/utils.py

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

Loading…
Cancel
Save