-
Notifications
You must be signed in to change notification settings - Fork 6
/
glTF_schema_validator.py
62 lines (50 loc) · 1.71 KB
/
glTF_schema_validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 19 11:50:04 2018
@author: kavisha
"""
#validate glTF
import json
import jsonschema
import time
import argparse
import sys
def glTFvalidate(inputFile,schemaFolder):
fInput = open(inputFile)
inputData = fInput.read()
j = json.loads(inputData)
fSchema = open(schemaFolder+ "glTF.schema.json")
inputSchema = fSchema.read()
js = json.loads(inputSchema)
resolver = jsonschema.RefResolver('file://' + schemaFolder, inputSchema)
print
try:
jsonschema.validate(j,js, resolver=resolver)
print("Passed derived schema.")
except Exception as ex:
print("Failed derived schema: %s" % ex)
#-------------start of program-------------------#
print ("\n****** glTF Validator *******\n")
argparser = argparse.ArgumentParser(description='******* glTF Validator *******')
argparser.add_argument('-i', '--inputFilename', help='glTF dataset filename', required=False)
argparser.add_argument('-schema', '--schemaFolderLocation', help='glTF schema folder (1.0/2.0)', required=False)
args = vars(argparser.parse_args())
inputFileName = args['inputFilename']
if inputFileName:
inputFile = str(inputFileName)
print ("CityGML input file: ", inputFile)
else:
print ("Error: Enter the glTF dataset!! ")
sys.exit()
schemaFolderLocation = args['schemaFolderLocation']
if schemaFolderLocation:
schemaFolder = str(schemaFolderLocation)
print ("glTF schema location: ", schemaFolder)
else:
print ("Error: Enter the glTF schema folder location!! ")
sys.exit()
start = time.time()
glTFvalidate(inputFile,schemaFolder)
end = time.time()
print ("\n Time taken for glTF validation: ",end - start, " sec")