Browse Source

Add a default songbook configuration

pull/184/head
Oliverpool 9 years ago
parent
commit
348345f220
  1. 67
      patacrep/data/templates/default_songbook.sb.yml
  2. 38
      patacrep/data/templates/songbook_schema.yml
  3. 32
      patacrep/songbook/__main__.py

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

@ -1,46 +1,51 @@
content:
book: book:
lang: en lang: en
datadir:
encoding: utf-8 encoding: utf-8
pictures: yes pictures: yes
chords: # Options relatives aux accords chords: # Options relatives aux accords
diagramreminder: ENUM[important, none, all] (anciennement importantdiagramonly) show: yes
diagrampage: BOOLEAN Montrer la page d'accords diagramreminder: all
repeatchords: BOOLEAN diagrampage: yes
lilypond: BOOLEAN repeatchords: yes
instruments: ENUM[guitar, ukulele] lilypond: yes
show: BOOLEAN (anciennement booktype=chorded ou booktype=lyrics) instruments: guitar
notation: ENUM[alphascale, solfedge] notation: alphascale
authors: # Comment sont analysés les auteurs authors: # Comment sont analysés les auteurs
separators: LISTE separators:
ignore: LISTE - To
by: LISTE - Do
ignore:
- To
- Do
by:
- To
- Do
titles: # Comment sont analysés les titres titles: # Comment sont analysés les titres
prefix: LISTE prefix:
- To
- Do
template: # Des choses spécifiques au template template: # Des choses spécifiques au template
file: STRING file: STRING
latex: # Des choses spécifiques au LaTeX # latex: # Des choses spécifiques au LaTeX
classoptions: STRING # classoptions: STRING
# Peut dépendre fortement du template # # Peut dépendre fortement du template
color: # Des couleurs # color: # Des couleurs
songnumber: STRING # songnumber: STRING
notebg: STRING # notebg: STRING
indexbg: STRING # indexbg: STRING
titlepage: #Configuration de la page de garde # titlepage: #Configuration de la page de garde
title: STRING # title: STRING
author: STRING # author: STRING
subtitle: STRING # subtitle: STRING
version: STRING # version: STRING
url: STRING # url: STRING
email: STRING # email: STRING
picture: STRING # picture: STRING
picturecopyright: STRING # picturecopyright: STRING
footer: STRING # footer: STRING

38
patacrep/data/templates/songbook_schema.yml

@ -1,9 +1,10 @@
type: //rec type: //rec
optional: optional:
content: //str content: //str
required:
book: book:
type: //rec type: //rec
optional: required:
encoding: //str encoding: //str
lang: //str lang: //str
pictures: //bool pictures: //bool
@ -12,7 +13,7 @@ optional:
contents: //str contents: //str
chords: chords:
type: //rec type: //rec
optional: required:
show: //bool show: //bool
diagrampage: //bool diagrampage: //bool
repeatchords: //bool repeatchords: //bool
@ -43,41 +44,54 @@ optional:
authors: authors:
_description: "Comment sont analysés les auteurs" _description: "Comment sont analysés les auteurs"
type: //rec type: //rec
optional: required:
separators: separators:
type: //arr type: //any
of:
- type: //arr
contents: //str contents: //str
- type: //nil
ignore: ignore:
type: //arr type: //any
of:
- type: //arr
contents: //str contents: //str
- type: //nil
by: by:
type: //arr type: //any
of:
- type: //arr
contents: //str contents: //str
- type: //nil
titles: titles:
_description: "Comment sont analysés les titres" _description: "Comment sont analysés les titres"
type: //rec type: //rec
optional: required:
prefix: prefix:
type: //arr type: //any
of:
- type: //arr
contents: //str contents: //str
- type: //nil
template: template:
_description: "Des choses spécifiques au template" _description: "Des choses spécifiques au template"
type: //rec type: //rec
optional: required:
file: //str file: //str
optional:
latex: latex:
type: //rec type: //rec
optional: required:
classoptions: //str classoptions: //str
color: color:
type: //rec type: //rec
optional: required:
songnumber: //str songnumber: //str
notebg: //str notebg: //str
indexbg: //str indexbg: //str
titlepage: titlepage:
type: //rec type: //rec
optional: required:
title: //str title: //str
author: //str author: //str
subtitle: //str subtitle: //str

32
patacrep/songbook/__main__.py

@ -9,9 +9,9 @@ import sys
import yaml import yaml
from patacrep.build import SongbookBuilder, DEFAULT_STEPS 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 __version__
from patacrep import errors from patacrep import errors, pkg_datapath
import patacrep.encoding import patacrep.encoding
# Logging configuration # Logging configuration
@ -133,39 +133,49 @@ def main():
basename = os.path.basename(songbook_path)[:-3] 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: try:
with patacrep.encoding.open_read(songbook_path) as songbook_file: with patacrep.encoding.open_read(songbook_path) as songbook_file:
songbook = yaml.load(songbook_file) user_songbook = yaml.load(songbook_file)
if 'encoding' in songbook: if 'encoding' in user_songbook:
with patacrep.encoding.open_read( with patacrep.encoding.open_read(
songbook_path, songbook_path,
encoding=songbook['encoding'] encoding=user_songbook['encoding']
) as songbook_file: ) as songbook_file:
songbook = yaml.load(songbook_file) user_songbook = yaml.load(songbook_file)
except Exception as error: # pylint: disable=broad-except except Exception as error: # pylint: disable=broad-except
LOGGER.error(error) LOGGER.error(error)
LOGGER.error("Error while loading file '{}'.".format(songbook_path)) LOGGER.error("Error while loading file '{}'.".format(songbook_path))
sys.exit(1) sys.exit(1)
# Merge the default and user configs
default_songbook.update(user_songbook)
songbook = dict(default_songbook)
# Gathering datadirs # Gathering datadirs
datadirs = [] datadirs = []
if options.datadir: if options.datadir:
# Command line options # Command line options
datadirs += [item[0] for item in options.datadir] datadirs += [item[0] for item in options.datadir]
if 'datadir' in songbook: if 'book' in songbook and 'datadir' in songbook['book']:
if isinstance(songbook['datadir'], str): if isinstance(songbook['book']['datadir'], str):
songbook['datadir'] = [songbook['datadir']] songbook['book']['datadir'] = [songbook['book']['datadir']]
datadirs += [ datadirs += [
os.path.join( os.path.join(
os.path.dirname(os.path.abspath(songbook_path)), os.path.dirname(os.path.abspath(songbook_path)),
path path
) )
for path in songbook['datadir'] for path in songbook['book']['datadir']
] ]
# 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['datadir'] = datadirs songbook['book']['datadir'] = datadirs
songbook['_cache'] = options.cache[0] songbook['_cache'] = options.cache[0]
try: try:

Loading…
Cancel
Save