Browse Source

Move config validation out of utils

pull/184/head
Oliverpool 9 years ago
parent
commit
a28169aa87
  1. 17
      patacrep/build.py
  2. 15
      patacrep/utils.py

17
patacrep/build.py

@ -8,7 +8,9 @@ import threading
import os.path
from subprocess import Popen, PIPE, call, check_call
from patacrep import authors, content, errors, files, utils
import yaml
from patacrep import authors, content, encoding, errors, files, pkg_datapath, utils
from patacrep.index import process_sxd
from patacrep.templates import TexBookRenderer, iter_bookoptions
from patacrep.songs import DataSubpath, DEFAULT_CONFIG
@ -42,11 +44,22 @@ class Songbook(object):
def __init__(self, raw_songbook, basename):
super().__init__()
self.config = raw_songbook
utils.validate_config_schema(raw_songbook)
self.validate_config_schema(raw_songbook)
self.basename = basename
# Some special keys have their value processed.
self._set_datadir()
@staticmethod
def validate_config_schema(raw_songbook):
"""
Check that the songbook config respects the excepted songbook schema
"""
schema_path = pkg_datapath('templates', 'songbook_schema.yml')
with encoding.open_read(schema_path) as schema_file:
schema_struct = yaml.load(schema_file)
schema_struct = utils.remove_keys(schema_struct, ['_description'])
utils.validate_yaml_schema(raw_songbook, schema_struct)
def _set_datadir(self):
"""Set the default values for datadir"""
abs_datadir = []

15
patacrep/utils.py

@ -2,7 +2,7 @@
from collections import UserDict
from patacrep import encoding, errors, pkg_datapath, Rx
from patacrep import errors, Rx
class DictOfDict(UserDict):
"""Dictionary, with a recursive :meth:`update` method.
@ -94,19 +94,6 @@ def remove_keys(data, keys=None, recursive=True):
return [remove_keys(elt, keys, True) for elt in data]
return data
def validate_config_schema(config):
"""
Check that the songbook config respects the excepted songbook schema
"""
data = config.copy()
schema_path = pkg_datapath('templates', 'songbook_schema.yml')
import yaml
with encoding.open_read(schema_path) as schema_file:
schema_struct = yaml.load(schema_file)
schema_struct = remove_keys(schema_struct, ['_description'])
validate_yaml_schema(data, schema_struct)
def validate_yaml_schema(data, schema):
"""
Check that the data respects the schema

Loading…
Cancel
Save