hyperion.ng/test/jsonchecks/checkeffects.py
redPanther 170ad4f5db improve serial hotplug (#389)
* - disable device when error indecates that the problem is not solvable on reconnect
- introduce a preOpenDelay of 2 seconds (currently value is hardcoded)

* rs232:
- make preOpenDelay available via webui
- fix preOpenDelay
- add basic usb serial detection

* - revert 3819ae7
- fix schema files

* make json checks compat with utf8+bom

* make shutdown effect a bit more flexible
2017-02-09 20:10:57 +01:00

51 lines
1.5 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.loads(baseSchemaFile.read().decode('utf-8-sig'))
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.loads(f.read().decode('utf-8-sig'))
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.loads(s.read().decode('utf-8-sig'))
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)