hyperion.ng/test/jsonchecks/checkeffects.py
redPanther 2c61b49b57 add json check before compile (#354)
* add json check before compile

* do more checking on effects

* add effects checking

* better effects checking.

* integrate schema check for default config
reduce size of default configs
2016-12-29 23:27:33 +01:00

51 lines
1.4 KiB
Python

#!/usr/bin/env python
import json, sys, glob
from os import path
from jsonschema import Draft3Validator
print("-- validate json effect files")
jsonFiles = sys.argv[1]
schemaFiles = sys.argv[2]
retval = 0
total = 0
errors = 0
with open("libsrc/effectengine/EffectDefinition.schema.json") as baseSchemaFile:
baseSchema = json.load(baseSchemaFile)
baseValidator = Draft3Validator(baseSchema)
for filename in glob.glob(jsonFiles+'/*.json'):
with open(filename) as f:
total += 1
msg = " check effect %s ... " % filename
try:
effect = json.load(f)
script = path.basename(effect['script'])
if not path.exists(jsonFiles+'/'+script):
raise ValueError('script file: '+script+' not found.')
schema = path.splitext(script)[0]+'.schema.json'
if not path.exists(jsonFiles+'/schema/'+schema):
raise ValueError('schema file: '+schema+' not found.')
schema = jsonFiles+'/schema/'+schema
# validate against schema
with open(schema) as s:
effectSchema = json.load(s)
Draft3Validator.check_schema(effectSchema)
validator = Draft3Validator(effectSchema)
baseValidator.validate(effect)
validator.validate(effect['args'])
#print(msg + "ok")
except Exception as e:
print(msg + 'error ('+str(e)+')')
errors += 1
retval = 1
print(" checked effect files: %s success: %s errors: %s" % (total,(total-errors),errors))
sys.exit(retval)