def bless_history(test_name, test_dir, baseline_name, baseline_root, report_only, force): ############################################################################### with Case(test_dir) as case: real_user = case.get_value("REALUSER") with EnvironmentContext(USER=real_user): if baseline_name is None: baseline_name = case.get_value("BASELINE_NAME_CMP") if not baseline_name: baseline_name = CIME.utils.get_current_branch(repo=CIME.utils.get_cime_root()) if baseline_root is None: baseline_root = case.get_value("BASELINE_ROOT") baseline_full_dir = os.path.join(baseline_root, baseline_name, case.get_value("CASEBASEID")) cmp_result, cmp_comments = compare_baseline(case, baseline_dir=baseline_full_dir, outfile_suffix=None) if cmp_result: logger.info("Diff appears to have been already resolved.") return True, None else: logger.info(cmp_comments) if (not report_only and (force or six.moves.input("Update this diff (y/n)? ").upper() in ["Y", "YES"])): gen_result, gen_comments = generate_baseline(case, baseline_dir=baseline_full_dir) if not gen_result: logger.warning("Hist file bless FAILED for test {}".format(test_name)) return False, "Generate baseline failed: {}".format(gen_comments) else: logger.info(gen_comments) return True, None else: return True, None
############################################################################### log_lvl = logging.getLogger().getEffectiveLevel() logging.disable(logging.CRITICAL) success = case.case_cmpgen_namelists(compare=True, compare_name=baseline_name, baseline_root=baseline_root, logfile_name=logfile_name) logging.getLogger().setLevel(log_lvl) return success ############################################################################### def compare_history(case, baseline_name, baseline_root, log_id): ############################################################################### real_user = case.get_value("REALUSER") with EnvironmentContext(USER=real_user): baseline_full_dir = os.path.join(baseline_root, baseline_name, case.get_value("CASEBASEID")) outfile_suffix = "{}.{}".format(baseline_name, log_id) try: result, comments = compare_baseline(case, baseline_dir=baseline_full_dir, outfile_suffix=outfile_suffix) except IOError: result, comments = compare_baseline(case, baseline_dir=baseline_full_dir, outfile_suffix=None) return result, comments