diff --git a/patacrep/build.py b/patacrep/build.py index 065c8604..114f121a 100644 --- a/patacrep/build.py +++ b/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'] diff --git a/patacrep/content/include.py b/patacrep/content/include.py index 30c99238..2948eb47 100644 --- a/patacrep/content/include.py +++ b/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( diff --git a/patacrep/content/tex.py b/patacrep/content/tex.py index 0f520c19..651eeba2 100755 --- a/patacrep/content/tex.py +++ b/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 diff --git a/patacrep/data/templates/default_songbook.sb.yml b/patacrep/data/templates/default_songbook.sb.yml index 70b44063..491eaa79 100644 --- a/patacrep/data/templates/default_songbook.sb.yml +++ b/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 diff --git a/patacrep/data/templates/songbook_schema.yml b/patacrep/data/templates/songbook_schema.yml index 4f47b185..8a5a20cd 100644 --- a/patacrep/data/templates/songbook_schema.yml +++ b/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 diff --git a/patacrep/songbook/__main__.py b/patacrep/songbook/__main__.py index 22e3ce66..9daff597 100644 --- a/patacrep/songbook/__main__.py +++ b/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: diff --git a/patacrep/songs/__init__.py b/patacrep/songs/__init__.py index d7619096..23c7900f 100644 --- a/patacrep/songs/__init__.py +++ b/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: diff --git a/patacrep/songs/convert/__main__.py b/patacrep/songs/convert/__main__.py index 19d7041e..1c2e8cfb 100644 --- a/patacrep/songs/convert/__main__.py +++ b/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'], diff --git a/patacrep/utils.py b/patacrep/utils.py index 54855b9f..e4b607b4 100644 --- a/patacrep/utils.py +++ b/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')