Commit 8343dadd authored by Eva Schiffer's avatar Eva Schiffer
Browse files

correcting return codes to reflect failure from missing variables

parent 639a0e17
......@@ -537,7 +537,7 @@ def report_one_input_library_call (a_path, var_list=None,
pathsTemp, runInfo, defaultValues, requestedNames, usedConfigFile = config_organizer.load_config_or_options(a_path, None, # there is no B path
options_set,
requestedVars = var_list)
# information for debugging purposes
LOG.debug('paths: ' + str(pathsTemp))
LOG.debug('defaults: ' + str(defaultValues))
......@@ -838,6 +838,7 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
pathsTemp, runInfo, defaultValues, requestedNames, usedConfigFile = config_organizer.load_config_or_options(a_path, b_path,
options_set,
requestedVars = var_list)
warn_on_missing = runInfo[OPTIONS_WARN_MISSING_KEY] if OPTIONS_WARN_MISSING_KEY in runInfo else False
# note some of this information for debugging purposes
LOG.debug('paths: ' + str(pathsTemp))
......@@ -848,10 +849,8 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
if (not runInfo[DO_MAKE_IMAGES_KEY]) and (not runInfo[DO_MAKE_REPORT_KEY]) :
LOG.warning("User selection of no image generation and no report generation will result in no " +
"content being generated. Aborting generation function.")
if do_pass_fail :
return 0 # nothing went wrong, we just had nothing to do!
else :
return 0
# nothing went wrong, we just had nothing to do!
return 0
# hang onto info to identify who/what/when/where/etc. the report is being run by/for
runInfo[MACHINE_INFO_KEY], runInfo[USER_INFO_KEY], runInfo[GLANCE_VERSION_INFO_KEY] = get_run_identification_info()
......@@ -880,7 +879,7 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
requestedNames,
usedConfigFile,
warnIfRequestedVarsUnavailable=
runInfo[OPTIONS_WARN_MISSING_KEY],)
warn_on_missing,)
# get info on the global attributes
globalAttrInfo = {}
......@@ -928,10 +927,11 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
variableStatsCollection = { }
# if we are warning about missing variables, right away add those to our list of variable comparisons
if runInfo[OPTIONS_WARN_MISSING_KEY] :
if warn_on_missing :
for varNameTemp in missingNames :
variableComparisons[varNameTemp] = _make_error_var_entry(missingNames[varNameTemp], do_pass_fail=do_pass_fail,)
didPassAll = False
# go through each of the possible variables in our files
# and make a report section with images for whichever ones we can
......@@ -949,8 +949,9 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
tmpMsg = displayName + " is of a type that cannot be loaded using current file handling libraries " \
"included with Glance. Skipping " + displayName + "."
LOG.warning(tmpMsg)
if runInfo[OPTIONS_WARN_MISSING_KEY] :
if warn_on_missing :
variableComparisons[explanationName] = _make_error_var_entry(tmpMsg, do_pass_fail=do_pass_fail,)
didPassAll = False
continue
LOG.info('analyzing: ' + explanationName)
......@@ -973,8 +974,9 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
tmpMsg = displayName + " data could not be loaded. This variable will not be included in the output report. " + \
"The following error was encountered while trying to load this variable:\n" + str(ex)
LOG.warning(tmpMsg)
if runInfo[OPTIONS_WARN_MISSING_KEY] :
if warn_on_missing :
variableComparisons[explanationName] = _make_error_var_entry(tmpMsg, do_pass_fail=do_pass_fail,)
didPassAll = False
continue
# get variable attribute information for this variable
......@@ -1040,8 +1042,7 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
varRunInfo[DID_VARIABLE_PASS_KEY] = didPass
# update the overall pass status
if didPass is not None :
didPassAll = didPassAll and didPass
didPassAll = didPassAll and didPass if didPass is not None else didPassAll
# based on the settings and whether the variable passed or failed,
# should we include images for this variable?
......@@ -1183,13 +1184,15 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
+ 'longitude ' + str(good_shape_from_lon_lat) + ' and '
+ 'latitude ' + str(good_shape_from_lon_lat) + ' variables.')
LOG.warning(message)
if runInfo[OPTIONS_WARN_MISSING_KEY] :
if warn_on_missing :
variableComparisons[explanationName] = _make_error_var_entry(message, do_pass_fail=do_pass_fail,)
didPassAll = False
except ValueErrorStringToFloat as ex:
tmpMsg = "Unable to compare "+displayName+": "+str(ex)
LOG.warning(tmpMsg)
if runInfo[OPTIONS_WARN_MISSING_KEY]:
if warn_on_missing :
variableComparisons[displayName] = _make_error_var_entry(tmpMsg, do_pass_fail=do_pass_fail,)
didPassAll = False
# the end of the loop to examine all the variables
......@@ -1221,9 +1224,8 @@ def report_two_inputs_library_call (a_path, b_path, var_list=None,
LOG.info ('generating glossary')
reportModule.generate_and_save_doc_page(statistics.StatisticalAnalysis.doc_strings(grouped=True), pathsTemp[OUT_FILE_KEY])
returnCode = 0 if didPassAll else 2 # return 2 only if some of the variables failed
# if we are reporting the pass / fail, return an appropriate status code
returnCode = 0 if didPassAll else 2 # return 2 only if some of the variables failed
to_return = returnCode if do_pass_fail else 0
if do_pass_fail :
LOG.debug("Pass/Fail return code: " + str(returnCode))
......@@ -1295,9 +1297,11 @@ def stats_two_inputs_library_call(afn, bfn, var_list=None,
# if we have command line input, we still need to parse the variable names
if not usedConfigFile:
temp_names, _ = config_organizer.parse_varnames(common_variable_names, requestedNames,
epsilon=default_epsilon, missing=default_fillval,
warn_unfound=warn_missing, )
temp_names, missing_names = config_organizer.parse_varnames(common_variable_names, requestedNames,
epsilon=default_epsilon, missing=default_fillval,
warn_unfound=warn_missing, )
if len(missing_names) > 0 and warn_missing and do_pass_fail :
has_failed = True
requestedNames = { }
for name, epsilon, missing in sorted(temp_names, key=lambda X: X[0]) :
requestedNames[name] = {
......@@ -1321,6 +1325,8 @@ def stats_two_inputs_library_call(afn, bfn, var_list=None,
if VARIABLE_TECH_NAME_KEY not in requestedNames[display_name] :
LOG.warning("Variable with display name of \"" + display_name + "\" has no technical name given. "
"This variable cannot be processed without a techincal name.")
if do_pass_fail and warn_missing :
has_failed = True
continue
tech_name = requestedNames[display_name][VARIABLE_TECH_NAME_KEY]
tech_b_name = tech_name if VARIABLE_B_TECH_NAME_KEY not in requestedNames[display_name] else requestedNames[display_name][VARIABLE_B_TECH_NAME_KEY]
......@@ -1335,17 +1341,23 @@ def stats_two_inputs_library_call(afn, bfn, var_list=None,
if warn_missing :
LOG.warning("Requested variable \"" + explain_name + "\" is not available in the A file. "
"Unable to process this variable.")
if do_pass_fail :
has_failed = True
continue
if tech_b_name not in b_var_names :
if warn_missing :
LOG.warning("Requested variable \"" + explain_name + "\" is not available in the B file. "
"Unable to process this variable.")
if do_pass_fail :
has_failed = True
continue
# make sure that it's possible to load this variable
if not(aFile.is_loadable_type(tech_name)) or not(bFile.is_loadable_type(tech_b_name)) :
LOG.warning(explain_name + " is of a type that cannot be loaded using current file handling "
"libraries included with Glance. Skipping " + explain_name + ".")
if do_pass_fail and warn_missing :
has_failed = True
continue
# load the variable data, filtering as needed
......@@ -1365,6 +1377,8 @@ def stats_two_inputs_library_call(afn, bfn, var_list=None,
except io.IONonnumericalTypeError as bad_data_error :
LOG.error("Skipping variable %s because it is of a non-numerical type "
"(may indicate array of variable-length strings): %s" % (explain_name, repr(bad_data_error)))
if do_pass_fail and warn_missing :
has_failed = True
continue
# figure out what fill values we're using to detect missing data
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment