Skip to content
Snippets Groups Projects
Commit d3f31d8a authored by Edward Fauchon-Jones's avatar Edward Fauchon-Jones
Browse files

Improve reporting of bad fields by `lvcnrcheck`

parent 03bf8c96
No related branches found
No related tags found
No related merge requests found
......@@ -34,25 +34,27 @@ parser.add_argument(
help='format level to use', type=int, choices=[1, 2, 3], default=1)
args = parser.parse_args()
# Define possible attribute output templates templates
VALID = u'- [{0:}={1:}] {{0:}} ({{1:}})'
WRONGTYPE = (
u'- [{0:}WRONG TYPE{1:}] {{0:}} ({{1:}}) '
u'(Type must be {{2:}})')
WRONGVALUE = (
u'- [{0:}INVALID VALUE{1:}] {{0:}} ({{1:}}) '
u'({{2:}})')
MISSING = u'- [{0:}MISSING{1:}] {{0:}} (undefined)'
# Define possible attribute output templates
VALID_COL = u'- [{0:}={1:}] {{0:}} ({{1:}})'.format(
Fore.GREEN,
Style.RESET_ALL)
WRONGTYPE_COL = u'- [{0:}TYPE{1:}] {{0:}} ({{1:}})'.format(
Fore.RED,
Style.RESET_ALL)
WRONGVALUE_COL = u'- [{0:}VALUE{1:}] {{0:}} ({{1:}})'.format(
Fore.RED,
Style.RESET_ALL)
MISSING_COL = u'- [{0:}MISSING{1:}] {{0:}} (undefined)'.format(
Fore.RED,
Style.RESET_ALL)
VALID_COL = VALID.format(Fore.GREEN, Style.RESET_ALL)
WRONGTYPE_COL = WRONGTYPE.format(Fore.RED, Style.RESET_ALL)
WRONGVALUE_COL = WRONGVALUE.format(Fore.RED, Style.RESET_ALL)
MISSING_COL = MISSING.format(Fore.RED, Style.RESET_ALL)
# Define possible attribute output templates without color
VALID_NOCOL = u'- [=] {0:} ({1:})'
WRONGTYPE_NOCOL = u'- [TYPE] {0:} ({1:})'
WRONGVALUE_NOCOL = u'- [VALUE] {0:} ({1:})'
MISSING_NOCOL = u'- [MISSING] {0:} (undefined)'
VALID_NOCOL = VALID.format('', '')
WRONGTYPE_NOCOL = WRONGTYPE.format('', '')
WRONGVALUE_NOCOL = WRONGVALUE.format('', '')
MISSING_NOCOL = MISSING.format('', '')
if args.col:
VALID = VALID_COL
......@@ -66,17 +68,19 @@ else:
MISSING = MISSING_NOCOL
def checkAttr(sim, attr, type, values=None):
def checkAttr(sim, attr, dtype, values=None):
value = sim.att(attr)
if value is not None:
if isinstance(value, type):
if isinstance(value, dtype):
if values is None or value in values:
print VALID.format(attr, value)
else:
print WRONGVALUE.format(attr, value)
strValues = ["{0:}".format(v) for v in values]
print WRONGVALUE.format(
attr, value, "Value must be one of "+", ".join(strValues))
else:
print WRONGTYPE.format(attr, value)
print WRONGTYPE.format(attr, value, dtype)
else:
print MISSING.format(attr)
......@@ -91,11 +95,13 @@ def checkDataset(sim, name, quantities):
if value:
if isinstance(value, h5.Dataset):
if len(value[0]) == quantities:
print VALID.format(name, 'HDF5-dataset')
print VALID.format(name, len(value[0]))
else:
print WRONGVALUE.format(name, len(value[0]))
print WRONGVALUE.format(
name, len(value[0]),
"Dataset must contain {0:d} columns".format(quantities))
else:
print WRONGTYPE.format(name, type(value))
print WRONGTYPE.format(name, type(value), h5.Dataset)
else:
print MISSING.format(name)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment