51 lines
1.6 KiB
Python
Executable File
51 lines
1.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import ucf
|
|
import argparse
|
|
import os
|
|
import sys
|
|
import traceback
|
|
|
|
parser = argparse.ArgumentParser(description='Tests basic integrity of a UCF file')
|
|
parser.add_argument('infile', metavar='file', nargs='+',help='input file')
|
|
parser.add_argument("--debug", help="enable debug output? [default: False]", action="store_true")
|
|
parser.add_argument("--print-error", help="print possible error messages? [default: False]", action="store_true")
|
|
parser.add_argument("--stop", help="stop as soon as a corrupted file has been found? [default: False]", action="store_true")
|
|
parser.add_argument("-v","--verbose", help="enable verbose output? [default: False]", action="store_true")
|
|
args = parser.parse_args()
|
|
|
|
file_in = args.infile
|
|
flag_debug = args.debug
|
|
flag_verbose = args.verbose
|
|
flag_error = args.print_error
|
|
flag_stop = args.stop
|
|
|
|
numerror=0
|
|
for file in file_in:
|
|
print(file+": ",end="")
|
|
if os.path.isfile(file)==False:
|
|
print('not found.')
|
|
numerror+=1
|
|
continue
|
|
try:
|
|
obj = ucf.UCF(file=file,verbosity=flag_verbose,debug=flag_debug)
|
|
for it in range(0,obj.NumTimestep):
|
|
for iset in range(0,obj._UCF__numSetPerStep[it]):
|
|
obj._UCF__findSet(it+1,iset+1)
|
|
obj._UCF__readHeaderSet()
|
|
obj.close()
|
|
print('successful ({:d} time steps, {:d} data sets)'.format(obj.NumTimestep,obj.NumDataset))
|
|
except Exception:
|
|
print('corrupt')
|
|
if flag_error:
|
|
print(traceback.print_exc())
|
|
if flag_stop:
|
|
sys.exit(1)
|
|
numerror+=1
|
|
|
|
if numerror==0:
|
|
print('Test completed with no errors.')
|
|
sys.exit(0)
|
|
else:
|
|
print("Test completed with {:d} error(s).".format(numerror))
|
|
sys.exit(1)
|