diff --git a/patacrep/data/templates/default_songbook.sb.yml b/patacrep/data/templates/default_songbook.sb.yml index 54a8291d..70b44063 100644 --- a/patacrep/data/templates/default_songbook.sb.yml +++ b/patacrep/data/templates/default_songbook.sb.yml @@ -1,46 +1,51 @@ -content: - book: lang: en - datadir: encoding: utf-8 pictures: yes chords: # Options relatives aux accords - diagramreminder: ENUM[important, none, all] (anciennement importantdiagramonly) - diagrampage: BOOLEAN Montrer la page d'accords - repeatchords: BOOLEAN - lilypond: BOOLEAN - instruments: ENUM[guitar, ukulele] - show: BOOLEAN (anciennement booktype=chorded ou booktype=lyrics) - notation: ENUM[alphascale, solfedge] + show: yes + diagramreminder: all + diagrampage: yes + repeatchords: yes + lilypond: yes + instruments: guitar + notation: alphascale authors: # Comment sont analysés les auteurs - separators: LISTE - ignore: LISTE - by: LISTE + separators: + - To + - Do + ignore: + - To + - Do + by: + - To + - Do titles: # Comment sont analysés les titres - prefix: LISTE + prefix: + - To + - Do template: # Des choses spécifiques au template file: STRING - latex: # Des choses spécifiques au LaTeX - classoptions: STRING + # latex: # Des choses spécifiques au LaTeX + # classoptions: STRING - # Peut dépendre fortement du template - color: # Des couleurs - songnumber: STRING - notebg: STRING - indexbg: STRING + # # Peut dépendre fortement du template + # color: # Des couleurs + # songnumber: STRING + # notebg: STRING + # indexbg: STRING - titlepage: #Configuration de la page de garde - title: STRING - author: STRING - subtitle: STRING - version: STRING - url: STRING - email: STRING - picture: STRING - picturecopyright: STRING - footer: STRING \ No newline at end of file + # titlepage: #Configuration de la page de garde + # title: STRING + # author: STRING + # subtitle: STRING + # version: STRING + # url: STRING + # email: STRING + # picture: STRING + # picturecopyright: STRING + # footer: STRING \ No newline at end of file diff --git a/patacrep/data/templates/songbook_schema.yml b/patacrep/data/templates/songbook_schema.yml index 6bbb7ba3..4f47b185 100644 --- a/patacrep/data/templates/songbook_schema.yml +++ b/patacrep/data/templates/songbook_schema.yml @@ -1,9 +1,10 @@ type: //rec optional: content: //str +required: book: type: //rec - optional: + required: encoding: //str lang: //str pictures: //bool @@ -12,7 +13,7 @@ optional: contents: //str chords: type: //rec - optional: + required: show: //bool diagrampage: //bool repeatchords: //bool @@ -43,41 +44,54 @@ optional: authors: _description: "Comment sont analysés les auteurs" type: //rec - optional: + required: separators: - type: //arr - contents: //str + type: //any + of: + - type: //arr + contents: //str + - type: //nil ignore: - type: //arr - contents: //str + type: //any + of: + - type: //arr + contents: //str + - type: //nil by: - type: //arr - contents: //str + type: //any + of: + - type: //arr + contents: //str + - type: //nil titles: _description: "Comment sont analysés les titres" type: //rec - optional: + required: prefix: - type: //arr - contents: //str + type: //any + of: + - type: //arr + contents: //str + - type: //nil template: _description: "Des choses spécifiques au template" type: //rec - optional: + required: file: //str + optional: latex: type: //rec - optional: + required: classoptions: //str color: type: //rec - optional: + required: songnumber: //str notebg: //str indexbg: //str titlepage: type: //rec - optional: + required: title: //str author: //str subtitle: //str diff --git a/patacrep/songbook/__main__.py b/patacrep/songbook/__main__.py index b62dcf73..22e3ce66 100644 --- a/patacrep/songbook/__main__.py +++ b/patacrep/songbook/__main__.py @@ -9,9 +9,9 @@ import sys import yaml from patacrep.build import SongbookBuilder, DEFAULT_STEPS -from patacrep.utils import yesno +from patacrep.utils import yesno, DictOfDict from patacrep import __version__ -from patacrep import errors +from patacrep import errors, pkg_datapath import patacrep.encoding # Logging configuration @@ -133,39 +133,49 @@ def main(): basename = os.path.basename(songbook_path)[:-3] + # Load the default songbook config + default_songbook_path = pkg_datapath('templates', 'default_songbook.sb.yml') + with patacrep.encoding.open_read(default_songbook_path) as default_songbook_file: + default_songbook = DictOfDict(yaml.load(default_songbook_file)) + + # Load the user songbook config try: with patacrep.encoding.open_read(songbook_path) as songbook_file: - songbook = yaml.load(songbook_file) - if 'encoding' in songbook: + user_songbook = yaml.load(songbook_file) + if 'encoding' in user_songbook: with patacrep.encoding.open_read( songbook_path, - encoding=songbook['encoding'] + encoding=user_songbook['encoding'] ) as songbook_file: - songbook = yaml.load(songbook_file) + user_songbook = yaml.load(songbook_file) except Exception as error: # pylint: disable=broad-except LOGGER.error(error) LOGGER.error("Error while loading file '{}'.".format(songbook_path)) sys.exit(1) + # Merge the default and user configs + default_songbook.update(user_songbook) + songbook = dict(default_songbook) + # Gathering datadirs datadirs = [] if options.datadir: # Command line options datadirs += [item[0] for item in options.datadir] - if 'datadir' in songbook: - if isinstance(songbook['datadir'], str): - songbook['datadir'] = [songbook['datadir']] + if 'book' in songbook and 'datadir' in songbook['book']: + 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 ) - for path in songbook['datadir'] + for path in songbook['book']['datadir'] ] # Default value datadirs.append(os.path.dirname(os.path.abspath(songbook_path))) - songbook['datadir'] = datadirs + songbook['book']['datadir'] = datadirs songbook['_cache'] = options.cache[0] try: