Browse Source

Remove _default and _description keys from the schema before using it

pull/184/head
Oliverpool 9 years ago
parent
commit
20012b4c29
  1. 7
      patacrep/build.py
  2. 3
      patacrep/data/templates/songbook_schema.yml
  3. 16
      patacrep/utils.py

7
patacrep/build.py

@ -10,7 +10,7 @@ from subprocess import Popen, PIPE, call, check_call
import yaml
from patacrep import authors, content, errors, encoding, files, pkg_datapath, Rx
from patacrep import authors, content, errors, encoding, files, pkg_datapath, Rx, utils
from patacrep.index import process_sxd
from patacrep.templates import TexBookRenderer
from patacrep.songs import DataSubpath, DEFAULT_CONFIG
@ -338,7 +338,10 @@ def check_config_schema(data):
rx_checker = Rx.Factory({"register_core_types": True})
schema_path = pkg_datapath('templates', 'songbook_schema.yml')
with encoding.open_read(schema_path) as schema_file:
schema = rx_checker.make_schema(yaml.load(schema_file))
schema_struct = yaml.load(schema_file)
schema_struct = utils.remove_keys(schema_struct, ['_default', '_description'])
schema = rx_checker.make_schema(schema_struct)
if schema.check(data):
return data
raise errors.SBFileError('The songbook file does not respect the schema')

3
patacrep/data/templates/songbook_schema.yml

@ -1 +1,2 @@
type: //any
type: //any
_default: "test"

16
patacrep/utils.py

@ -75,3 +75,19 @@ def yesno(string):
string,
", ".join(["'{}'".format(string) for string in yes_strings + no_strings]),
))
def remove_keys(data, keys=None, recursive=True):
"""
Remove the keys of the dict
"""
if isinstance(data, dict):
for key in keys:
if key in data:
del data[key]
if recursive:
for key in data:
data[key] = remove_keys(data[key], keys, True)
return data
elif isinstance(data, list) and recursive:
return [remove_keys(elt, keys, True) for elt in data]
return data

Loading…
Cancel
Save