From bafc903094eda5bf0dd1e67c12aa3e68915a5f78 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 2 Dec 2016 05:59:03 -0700 Subject: [PATCH 1/2] trap on perl buildnml --- utils/python/CIME/preview_namelists.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/python/CIME/preview_namelists.py b/utils/python/CIME/preview_namelists.py index 81f989e9fbc..be3fec5ace3 100644 --- a/utils/python/CIME/preview_namelists.py +++ b/utils/python/CIME/preview_namelists.py @@ -69,7 +69,7 @@ def create_namelists(case): os.path.join(config_dir, "buildnml")) logger.info("Calling %s buildnml"%compname) mod.buildnml(case, caseroot, compname) - except AttributeError: + except (AttributeError, SyntaxError): cmd = os.path.join(config_dir, "buildnml") run_cmd_no_fail("%s %s" % (cmd, caseroot), verbose=True) except: From 08cecc51150c0e104f817b31208ef4037bb9df3f Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Fri, 2 Dec 2016 06:13:08 -0700 Subject: [PATCH 2/2] raise error if file is python --- utils/python/CIME/preview_namelists.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/utils/python/CIME/preview_namelists.py b/utils/python/CIME/preview_namelists.py index be3fec5ace3..d487f398c1b 100644 --- a/utils/python/CIME/preview_namelists.py +++ b/utils/python/CIME/preview_namelists.py @@ -64,13 +64,20 @@ def create_namelists(case): compname = "drv" else: compname = case.get_value("COMP_%s" % model_str.upper()) + cmd = os.path.join(config_dir, "buildnml") try: - mod = imp.load_source("buildnml", - os.path.join(config_dir, "buildnml")) + mod = imp.load_source("buildnml", cmd) logger.info("Calling %s buildnml"%compname) mod.buildnml(case, caseroot, compname) - except (AttributeError, SyntaxError): - cmd = os.path.join(config_dir, "buildnml") + + except SyntaxError as detail: + with open(cmd, 'r') as f: + first_line = f.readline() + if 'python' in first_line: + expect(False, detail) + else: + run_cmd_no_fail("%s %s" % (cmd, caseroot), verbose=True) + except AttributeError: run_cmd_no_fail("%s %s" % (cmd, caseroot), verbose=True) except: raise