2016-12-29 23:27:33 +01:00
|
|
|
#!/usr/bin/env python
|
2017-02-09 20:10:57 +01:00
|
|
|
import json, sys, glob
|
2016-12-29 23:27:33 +01:00
|
|
|
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:
|
2017-02-09 20:10:57 +01:00
|
|
|
baseSchema = json.loads(baseSchemaFile.read().decode('utf-8-sig'))
|
2016-12-29 23:27:33 +01:00
|
|
|
baseValidator = Draft3Validator(baseSchema)
|
|
|
|
for filename in glob.glob(jsonFiles+'/*.json'):
|
|
|
|
with open(filename) as f:
|
|
|
|
total += 1
|
|
|
|
msg = " check effect %s ... " % filename
|
|
|
|
try:
|
2017-02-09 20:10:57 +01:00
|
|
|
effect = json.loads(f.read().decode('utf-8-sig'))
|
2016-12-29 23:27:33 +01:00
|
|
|
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:
|
2017-02-09 20:10:57 +01:00
|
|
|
effectSchema = json.loads(s.read().decode('utf-8-sig'))
|
2016-12-29 23:27:33 +01:00
|
|
|
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)
|