Skip to content

Commit

Permalink
Attempt to fix the validator
Browse files Browse the repository at this point in the history
  • Loading branch information
sundhaug92 authored Dec 13, 2023
1 parent c1ee124 commit ad8bcf0
Showing 1 changed file with 35 additions and 16 deletions.
51 changes: 35 additions & 16 deletions tools/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
'AutoGenerate'
]

main_key_fields_ignorable = [
'AutoGenerate'
]

main_key_types = {
'checklistText': str,
'Group': str,
Expand All @@ -32,7 +36,11 @@
'AutoGenerate': bool
}

step_key_fields = ['Program', 'Type', 'SetID', 'ToPosID', 'Text']
step_key_fields = ['Program', 'Type', 'SetID', 'ToPosID', 'Text', 'Description']

step_key_fields_ignorable = ['Description']

# TODO: step_key_types

image_key_fields = ['Name', 'Position', 'Size']

Expand All @@ -51,12 +59,15 @@
file_ok = True
for main_key in main_key_fields:
if main_key not in j.keys():
print(checklist, 'MAIN', main_key, 'MISSING')
file_ok = False
all_valid = False
if main_key in main_key_fields_ignorable:
print(checklist, 'MAIN', main_key, 'MISSING (OPTIONAL)')
else:
print(checklist, 'MAIN', main_key, 'MISSING')
file_ok = False
all_valid = False
for main_key in j.keys():
if main_key not in main_key_fields:
print(checklist, 'MAIN', main_key, 'Invalid key')
print(checklist, 'MAIN', main_key, 'Invalid (unknown) key')
file_ok = False
all_valid = False
if type(j[main_key]) != main_key_types[main_key]:
Expand All @@ -69,27 +80,31 @@
continue
for step_key in step_key_fields:
if step_key not in step.keys():
print(checklist, 'STEP', step_key, 'MISSING')
file_ok = False
all_valid = False
if step_key in step_key_fields_ignorable:
print(checklist, 'STEP', step_key, 'MISSING (OPTIONAL)')
else:
print(checklist, 'STEP', step_key, 'MISSING')
file_ok = False
all_valid = False
if step_key not in step_key_fields:
print(checklist, 'STEP', step_key, 'Invalid key')
print(checklist, 'STEP', step_key, 'Invalid (unknown) key')
file_ok = False
all_valid = False
for step_key in step.keys():
if step_key not in step_key_fields:
print(checklist, 'STEP', step_key, 'Key has wrong type')
file_ok = False
all_valid = False
# TODO: Add type-validation for step-keys. One issue is that NULL appears to be a valid value for Text
# if type(step_key) not in step_key_types[step_key]:
# print(checklist, 'STEP', step_key, 'Key has wrong type')
# file_ok = False
# all_valid = False
pass
for image in j['Images']:
for image_key in image_key_fields:
if image_key not in image.keys():
print(checklist, 'IMAGE', image_key, 'MISSING')
file_ok = False
all_valid = False
if image_key not in image_key_fields:
print(checklist, 'IMAGE', image_key, 'Invalid key')
print(checklist, 'IMAGE', image_key, 'Invalid (unknown) key')
file_ok = False
all_valid = False
if type(image[image_key]) != image_key_types[image_key]:
Expand All @@ -105,7 +120,11 @@
print(checklist, 'IMAGE', image_path, 'File not found')
file_ok = False
all_valid = False
with Image.open(image_path) as im:
pass # ATM, just "this is a valid image" is enough
try:
with Image.open(image_path) as im:
pass # ATM, just "this is a valid image" is enough
except:
file_ok = False
all_valid = False

sys.exit(0 if all_valid else -1)

0 comments on commit ad8bcf0

Please sign in to comment.