We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
bless_test_results - can not find create_test command
I am using tag:
 https://github.com/CESM-Development/cime/tags/cime5.2.0-alpha.10

When I issue the command:
 /glade/u/home/cacraig/cam5_4_94/cime/scripts/Tools/bless_test_results  -t '' -c '' -r /glade/scratch/cacraig/aux_cam_20161123172411 -b cam5_4_94-copy6 -f

I get the following error:
FAILED TO BLESS TEST: SMS_Lm13.f09_f09.F2000_DEV.yellowstone_intel.cam-outfrq1m_clm5, reason Namelist regen failed: '/bin/sh: create_test: command not found'

The baseline directory created by this script has the netCDF files in it, but no namelists are copied.  I've tried running this command from various locations including the cime/scripts directory where create_test resides, and can not eliminate this error.



--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `utils/python/CIME/case_cmpgen_namelists.py`
Content:
```
1 """
2 Library for case.cmpgen_namelists.
3 """
4 
5 from CIME.XML.standard_module_setup import *
6 
7 from CIME.preview_namelists import create_namelists
8 from CIME.compare_namelists import is_namelist_file, compare_namelist_files
9 from CIME.simple_compare import compare_files
10 from CIME.utils import get_current_branch, append_status
11 from CIME.test_status import *
12 
13 import os, shutil, traceback, stat, glob
14 
15 logger = logging.getLogger(__name__)
16 
17 def _do_full_nl_comp(case, test, compare_name):
18     test_dir       = case.get_value("CASEROOT")
19     casedoc_dir    = os.path.join(test_dir, "CaseDocs")
20     baseline_root  = case.get_value("BASELINE_ROOT")
21 
22     all_match         = True
23     baseline_dir      = os.path.join(baseline_root, compare_name, test)
24     baseline_casedocs = os.path.join(baseline_dir, "CaseDocs")
25 
26     # Start off by comparing everything in CaseDocs except a few arbitrary files (ugh!)
27     # TODO: Namelist files should have consistent suffix
28     all_items_to_compare = [item for item in glob.glob("%s/*" % casedoc_dir)\
29                             if "README" not in os.path.basename(item)\
30                             and not item.endswith("doc")\
31                             and not item.endswith("prescribed")\
32                             and not os.path.basename(item).startswith(".")] + \
33                             glob.glob("%s/*user_nl*" % test_dir)
34 
35     comments = ""
36     for item in all_items_to_compare:
37         baseline_counterpart = os.path.join(baseline_casedocs \
38                                             if os.path.dirname(item).endswith("CaseDocs") \
39                                             else baseline_dir,os.path.basename(item))
40         if not os.path.exists(baseline_counterpart):
41             comments += "Missing baseline namelist '%s'\n" % baseline_counterpart
42             all_match = False
43         else:
44             if is_namelist_file(item):
45                 success, current_comments = compare_namelist_files(baseline_counterpart, item, test)
46             else:
47                 success, current_comments = compare_files(baseline_counterpart, item, test)
48 
49             all_match &= success
50             comments += current_comments
51 
52     logging.info(comments)
53     return all_match, comments
54 
55 def _do_full_nl_gen(case, test, generate_name):
56     test_dir       = case.get_value("CASEROOT")
57     casedoc_dir    = os.path.join(test_dir, "CaseDocs")
58     baseline_root  = case.get_value("BASELINE_ROOT")
59 
60     baseline_dir      = os.path.join(baseline_root, generate_name, test)
61     baseline_casedocs = os.path.join(baseline_dir, "CaseDocs")
62 
63     if not os.path.isdir(baseline_dir):
64         os.makedirs(baseline_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IXOTH | stat.S_IROTH)
65 
66     if os.path.isdir(baseline_casedocs):
67         shutil.rmtree(baseline_casedocs)
68 
69     shutil.copytree(casedoc_dir, baseline_casedocs)
70     os.chmod(baseline_casedocs, stat.S_IRWXU | stat.S_IRWXG | stat.S_IXOTH | stat.S_IROTH)
71     for item in glob.glob("%s/*" % baseline_casedocs):
72         os.chmod(item, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
73 
74     for item in glob.glob(os.path.join(test_dir, "user_nl*")):
75         preexisting_baseline = os.path.join(baseline_dir, os.path.basename(item))
76         if (os.path.exists(preexisting_baseline)):
77             os.remove(preexisting_baseline)
78 
79         shutil.copy2(item, baseline_dir)
80         os.chmod(preexisting_baseline, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
81 
82 def case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None):
83     expect(case.get_value("TEST"), "Only makes sense to run this for a test case")
84 
85     caseroot, casebaseid = case.get_value("CASEROOT"), case.get_value("CASEBASEID")
86 
87     if not compare:
88         compare = case.get_value("COMPARE_BASELINE")
89     if not generate:
90         generate = case.get_value("GENERATE_BASELINE")
91 
92     if not compare and not generate:
93         logging.info("Nothing to do")
94         return True
95 
96     # create namelists for case if they haven't been already
97     casedocs = os.path.join(caseroot, "CaseDocs")
98     if not os.path.exists(os.path.join(casedocs, "drv_in")):
99         create_namelists(case)
100 
101     test_name = casebaseid if casebaseid is not None else case.get_value("CASE")
102     with TestStatus(test_dir=caseroot, test_name=test_name) as ts:
103         try:
104             # Inside this try are where we catch non-fatal errors, IE errors involving
105             # baseline operations which may not directly impact the functioning of the viability of this case
106             if compare and not compare_name:
107                 compare_name = case.get_value("BASELINE_NAME_CMP")
108                 compare_name = get_current_branch() if compare_name is None else compare_name
109                 expect(compare_name, "Was asked to do baseline compare but unable to determine baseline name")
110                 logging.info("Comparing namelists with baselines '%s'" % compare_name)
111             if generate and not generate_name:
112                 generate_name = case.get_value("BASELINE_NAME_GEN")
113                 generate_name = get_current_branch() if generate_name is None else generate_name
114                 expect(generate_name, "Was asked to do baseline generation but unable to determine baseline name")
115                 logging.info("Generating namelists to baselines '%s'" % generate_name)
116 
117             success = True
118             output = ""
119             if compare:
120                 success, output = _do_full_nl_comp(case, test_name, compare_name)
121             if generate:
122                 _do_full_nl_gen(case, test_name, generate_name)
123         except:
124             ts.set_status(NAMELIST_PHASE, TEST_FAIL_STATUS)
125             success = False
126             warn = "Exception during namelist operations:\n%s\n%s" % (sys.exc_info()[1], traceback.format_exc())
127             output += warn
128             logging.warning(warn)
129         finally:
130             ts.set_status(NAMELIST_PHASE, TEST_PASS_STATUS if success else TEST_FAIL_STATUS)
131             append_status(output, caseroot=caseroot, sfile="TestStatus.log")
132 
133         return success
134 
135
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/utils/python/CIME/case_cmpgen_namelists.py b/utils/python/CIME/case_cmpgen_namelists.py
--- a/utils/python/CIME/case_cmpgen_namelists.py
+++ b/utils/python/CIME/case_cmpgen_namelists.py
@@ -14,10 +14,10 @@
 
 logger = logging.getLogger(__name__)
 
-def _do_full_nl_comp(case, test, compare_name):
+def _do_full_nl_comp(case, test, compare_name, baseline_root=None):
     test_dir       = case.get_value("CASEROOT")
     casedoc_dir    = os.path.join(test_dir, "CaseDocs")
-    baseline_root  = case.get_value("BASELINE_ROOT")
+    baseline_root  = case.get_value("BASELINE_ROOT") if baseline_root is None else baseline_root
 
     all_match         = True
     baseline_dir      = os.path.join(baseline_root, compare_name, test)
@@ -52,10 +52,10 @@
     logging.info(comments)
     return all_match, comments
 
-def _do_full_nl_gen(case, test, generate_name):
+def _do_full_nl_gen(case, test, generate_name, baseline_root=None):
     test_dir       = case.get_value("CASEROOT")
     casedoc_dir    = os.path.join(test_dir, "CaseDocs")
-    baseline_root  = case.get_value("BASELINE_ROOT")
+    baseline_root  = case.get_value("BASELINE_ROOT") if baseline_root is None else baseline_root
 
     baseline_dir      = os.path.join(baseline_root, generate_name, test)
     baseline_casedocs = os.path.join(baseline_dir, "CaseDocs")
@@ -79,7 +79,7 @@
         shutil.copy2(item, baseline_dir)
         os.chmod(preexisting_baseline, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)
 
-def case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None):
+def case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None, baseline_root=None, logfile_name="TestStatus.log"):
     expect(case.get_value("TEST"), "Only makes sense to run this for a test case")
 
     caseroot, casebaseid = case.get_value("CASEROOT"), case.get_value("CASEBASEID")
@@ -117,9 +117,9 @@
             success = True
             output = ""
             if compare:
-                success, output = _do_full_nl_comp(case, test_name, compare_name)
+                success, output = _do_full_nl_comp(case, test_name, compare_name, baseline_root)
             if generate:
-                _do_full_nl_gen(case, test_name, generate_name)
+                _do_full_nl_gen(case, test_name, generate_name, baseline_root)
         except:
             ts.set_status(NAMELIST_PHASE, TEST_FAIL_STATUS)
             success = False
@@ -128,7 +128,7 @@
             logging.warning(warn)
         finally:
             ts.set_status(NAMELIST_PHASE, TEST_PASS_STATUS if success else TEST_FAIL_STATUS)
-            append_status(output, caseroot=caseroot, sfile="TestStatus.log")
+            append_status(output, caseroot=caseroot, sfile=logfile_name)
 
         return success

{"golden_diff": "diff --git a/utils/python/CIME/case_cmpgen_namelists.py b/utils/python/CIME/case_cmpgen_namelists.py\n--- a/utils/python/CIME/case_cmpgen_namelists.py\n+++ b/utils/python/CIME/case_cmpgen_namelists.py\n@@ -14,10 +14,10 @@\n \n logger = logging.getLogger(__name__)\n \n-def _do_full_nl_comp(case, test, compare_name):\n+def _do_full_nl_comp(case, test, compare_name, baseline_root=None):\n     test_dir       = case.get_value(\"CASEROOT\")\n     casedoc_dir    = os.path.join(test_dir, \"CaseDocs\")\n-    baseline_root  = case.get_value(\"BASELINE_ROOT\")\n+    baseline_root  = case.get_value(\"BASELINE_ROOT\") if baseline_root is None else baseline_root\n \n     all_match         = True\n     baseline_dir      = os.path.join(baseline_root, compare_name, test)\n@@ -52,10 +52,10 @@\n     logging.info(comments)\n     return all_match, comments\n \n-def _do_full_nl_gen(case, test, generate_name):\n+def _do_full_nl_gen(case, test, generate_name, baseline_root=None):\n     test_dir       = case.get_value(\"CASEROOT\")\n     casedoc_dir    = os.path.join(test_dir, \"CaseDocs\")\n-    baseline_root  = case.get_value(\"BASELINE_ROOT\")\n+    baseline_root  = case.get_value(\"BASELINE_ROOT\") if baseline_root is None else baseline_root\n \n     baseline_dir      = os.path.join(baseline_root, generate_name, test)\n     baseline_casedocs = os.path.join(baseline_dir, \"CaseDocs\")\n@@ -79,7 +79,7 @@\n         shutil.copy2(item, baseline_dir)\n         os.chmod(preexisting_baseline, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)\n \n-def case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None):\n+def case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None, baseline_root=None, logfile_name=\"TestStatus.log\"):\n     expect(case.get_value(\"TEST\"), \"Only makes sense to run this for a test case\")\n \n     caseroot, casebaseid = case.get_value(\"CASEROOT\"), case.get_value(\"CASEBASEID\")\n@@ -117,9 +117,9 @@\n             success = True\n             output = \"\"\n             if compare:\n-                success, output = _do_full_nl_comp(case, test_name, compare_name)\n+                success, output = _do_full_nl_comp(case, test_name, compare_name, baseline_root)\n             if generate:\n-                _do_full_nl_gen(case, test_name, generate_name)\n+                _do_full_nl_gen(case, test_name, generate_name, baseline_root)\n         except:\n             ts.set_status(NAMELIST_PHASE, TEST_FAIL_STATUS)\n             success = False\n@@ -128,7 +128,7 @@\n             logging.warning(warn)\n         finally:\n             ts.set_status(NAMELIST_PHASE, TEST_PASS_STATUS if success else TEST_FAIL_STATUS)\n-            append_status(output, caseroot=caseroot, sfile=\"TestStatus.log\")\n+            append_status(output, caseroot=caseroot, sfile=logfile_name)\n \n         return success\n", "issue": "bless_test_results - can not find create_test command\nI am using tag:\r\n https://github.com/CESM-Development/cime/tags/cime5.2.0-alpha.10\r\n\r\nWhen I issue the command:\r\n /glade/u/home/cacraig/cam5_4_94/cime/scripts/Tools/bless_test_results  -t '' -c '' -r /glade/scratch/cacraig/aux_cam_20161123172411 -b cam5_4_94-copy6 -f\r\n\r\nI get the following error:\r\nFAILED TO BLESS TEST: SMS_Lm13.f09_f09.F2000_DEV.yellowstone_intel.cam-outfrq1m_clm5, reason Namelist regen failed: '/bin/sh: create_test: command not found'\r\n\r\nThe baseline directory created by this script has the netCDF files in it, but no namelists are copied.  I've tried running this command from various locations including the cime/scripts directory where create_test resides, and can not eliminate this error.\r\n\r\n\n", "before_files": [{"content": "\"\"\"\nLibrary for case.cmpgen_namelists.\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\n\nfrom CIME.preview_namelists import create_namelists\nfrom CIME.compare_namelists import is_namelist_file, compare_namelist_files\nfrom CIME.simple_compare import compare_files\nfrom CIME.utils import get_current_branch, append_status\nfrom CIME.test_status import *\n\nimport os, shutil, traceback, stat, glob\n\nlogger = logging.getLogger(__name__)\n\ndef _do_full_nl_comp(case, test, compare_name):\n    test_dir       = case.get_value(\"CASEROOT\")\n    casedoc_dir    = os.path.join(test_dir, \"CaseDocs\")\n    baseline_root  = case.get_value(\"BASELINE_ROOT\")\n\n    all_match         = True\n    baseline_dir      = os.path.join(baseline_root, compare_name, test)\n    baseline_casedocs = os.path.join(baseline_dir, \"CaseDocs\")\n\n    # Start off by comparing everything in CaseDocs except a few arbitrary files (ugh!)\n    # TODO: Namelist files should have consistent suffix\n    all_items_to_compare = [item for item in glob.glob(\"%s/*\" % casedoc_dir)\\\n                            if \"README\" not in os.path.basename(item)\\\n                            and not item.endswith(\"doc\")\\\n                            and not item.endswith(\"prescribed\")\\\n                            and not os.path.basename(item).startswith(\".\")] + \\\n                            glob.glob(\"%s/*user_nl*\" % test_dir)\n\n    comments = \"\"\n    for item in all_items_to_compare:\n        baseline_counterpart = os.path.join(baseline_casedocs \\\n                                            if os.path.dirname(item).endswith(\"CaseDocs\") \\\n                                            else baseline_dir,os.path.basename(item))\n        if not os.path.exists(baseline_counterpart):\n            comments += \"Missing baseline namelist '%s'\\n\" % baseline_counterpart\n            all_match = False\n        else:\n            if is_namelist_file(item):\n                success, current_comments = compare_namelist_files(baseline_counterpart, item, test)\n            else:\n                success, current_comments = compare_files(baseline_counterpart, item, test)\n\n            all_match &= success\n            comments += current_comments\n\n    logging.info(comments)\n    return all_match, comments\n\ndef _do_full_nl_gen(case, test, generate_name):\n    test_dir       = case.get_value(\"CASEROOT\")\n    casedoc_dir    = os.path.join(test_dir, \"CaseDocs\")\n    baseline_root  = case.get_value(\"BASELINE_ROOT\")\n\n    baseline_dir      = os.path.join(baseline_root, generate_name, test)\n    baseline_casedocs = os.path.join(baseline_dir, \"CaseDocs\")\n\n    if not os.path.isdir(baseline_dir):\n        os.makedirs(baseline_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IXOTH | stat.S_IROTH)\n\n    if os.path.isdir(baseline_casedocs):\n        shutil.rmtree(baseline_casedocs)\n\n    shutil.copytree(casedoc_dir, baseline_casedocs)\n    os.chmod(baseline_casedocs, stat.S_IRWXU | stat.S_IRWXG | stat.S_IXOTH | stat.S_IROTH)\n    for item in glob.glob(\"%s/*\" % baseline_casedocs):\n        os.chmod(item, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)\n\n    for item in glob.glob(os.path.join(test_dir, \"user_nl*\")):\n        preexisting_baseline = os.path.join(baseline_dir, os.path.basename(item))\n        if (os.path.exists(preexisting_baseline)):\n            os.remove(preexisting_baseline)\n\n        shutil.copy2(item, baseline_dir)\n        os.chmod(preexisting_baseline, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)\n\ndef case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None):\n    expect(case.get_value(\"TEST\"), \"Only makes sense to run this for a test case\")\n\n    caseroot, casebaseid = case.get_value(\"CASEROOT\"), case.get_value(\"CASEBASEID\")\n\n    if not compare:\n        compare = case.get_value(\"COMPARE_BASELINE\")\n    if not generate:\n        generate = case.get_value(\"GENERATE_BASELINE\")\n\n    if not compare and not generate:\n        logging.info(\"Nothing to do\")\n        return True\n\n    # create namelists for case if they haven't been already\n    casedocs = os.path.join(caseroot, \"CaseDocs\")\n    if not os.path.exists(os.path.join(casedocs, \"drv_in\")):\n        create_namelists(case)\n\n    test_name = casebaseid if casebaseid is not None else case.get_value(\"CASE\")\n    with TestStatus(test_dir=caseroot, test_name=test_name) as ts:\n        try:\n            # Inside this try are where we catch non-fatal errors, IE errors involving\n            # baseline operations which may not directly impact the functioning of the viability of this case\n            if compare and not compare_name:\n                compare_name = case.get_value(\"BASELINE_NAME_CMP\")\n                compare_name = get_current_branch() if compare_name is None else compare_name\n                expect(compare_name, \"Was asked to do baseline compare but unable to determine baseline name\")\n                logging.info(\"Comparing namelists with baselines '%s'\" % compare_name)\n            if generate and not generate_name:\n                generate_name = case.get_value(\"BASELINE_NAME_GEN\")\n                generate_name = get_current_branch() if generate_name is None else generate_name\n                expect(generate_name, \"Was asked to do baseline generation but unable to determine baseline name\")\n                logging.info(\"Generating namelists to baselines '%s'\" % generate_name)\n\n            success = True\n            output = \"\"\n            if compare:\n                success, output = _do_full_nl_comp(case, test_name, compare_name)\n            if generate:\n                _do_full_nl_gen(case, test_name, generate_name)\n        except:\n            ts.set_status(NAMELIST_PHASE, TEST_FAIL_STATUS)\n            success = False\n            warn = \"Exception during namelist operations:\\n%s\\n%s\" % (sys.exc_info()[1], traceback.format_exc())\n            output += warn\n            logging.warning(warn)\n        finally:\n            ts.set_status(NAMELIST_PHASE, TEST_PASS_STATUS if success else TEST_FAIL_STATUS)\n            append_status(output, caseroot=caseroot, sfile=\"TestStatus.log\")\n\n        return success\n\n", "path": "utils/python/CIME/case_cmpgen_namelists.py"}], "after_files": [{"content": "\"\"\"\nLibrary for case.cmpgen_namelists.\n\"\"\"\n\nfrom CIME.XML.standard_module_setup import *\n\nfrom CIME.preview_namelists import create_namelists\nfrom CIME.compare_namelists import is_namelist_file, compare_namelist_files\nfrom CIME.simple_compare import compare_files\nfrom CIME.utils import get_current_branch, append_status\nfrom CIME.test_status import *\n\nimport os, shutil, traceback, stat, glob\n\nlogger = logging.getLogger(__name__)\n\ndef _do_full_nl_comp(case, test, compare_name, baseline_root=None):\n    test_dir       = case.get_value(\"CASEROOT\")\n    casedoc_dir    = os.path.join(test_dir, \"CaseDocs\")\n    baseline_root  = case.get_value(\"BASELINE_ROOT\") if baseline_root is None else baseline_root\n\n    all_match         = True\n    baseline_dir      = os.path.join(baseline_root, compare_name, test)\n    baseline_casedocs = os.path.join(baseline_dir, \"CaseDocs\")\n\n    # Start off by comparing everything in CaseDocs except a few arbitrary files (ugh!)\n    # TODO: Namelist files should have consistent suffix\n    all_items_to_compare = [item for item in glob.glob(\"%s/*\" % casedoc_dir)\\\n                            if \"README\" not in os.path.basename(item)\\\n                            and not item.endswith(\"doc\")\\\n                            and not item.endswith(\"prescribed\")\\\n                            and not os.path.basename(item).startswith(\".\")] + \\\n                            glob.glob(\"%s/*user_nl*\" % test_dir)\n\n    comments = \"\"\n    for item in all_items_to_compare:\n        baseline_counterpart = os.path.join(baseline_casedocs \\\n                                            if os.path.dirname(item).endswith(\"CaseDocs\") \\\n                                            else baseline_dir,os.path.basename(item))\n        if not os.path.exists(baseline_counterpart):\n            comments += \"Missing baseline namelist '%s'\\n\" % baseline_counterpart\n            all_match = False\n        else:\n            if is_namelist_file(item):\n                success, current_comments = compare_namelist_files(baseline_counterpart, item, test)\n            else:\n                success, current_comments = compare_files(baseline_counterpart, item, test)\n\n            all_match &= success\n            comments += current_comments\n\n    logging.info(comments)\n    return all_match, comments\n\ndef _do_full_nl_gen(case, test, generate_name, baseline_root=None):\n    test_dir       = case.get_value(\"CASEROOT\")\n    casedoc_dir    = os.path.join(test_dir, \"CaseDocs\")\n    baseline_root  = case.get_value(\"BASELINE_ROOT\") if baseline_root is None else baseline_root\n\n    baseline_dir      = os.path.join(baseline_root, generate_name, test)\n    baseline_casedocs = os.path.join(baseline_dir, \"CaseDocs\")\n\n    if not os.path.isdir(baseline_dir):\n        os.makedirs(baseline_dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IXOTH | stat.S_IROTH)\n\n    if os.path.isdir(baseline_casedocs):\n        shutil.rmtree(baseline_casedocs)\n\n    shutil.copytree(casedoc_dir, baseline_casedocs)\n    os.chmod(baseline_casedocs, stat.S_IRWXU | stat.S_IRWXG | stat.S_IXOTH | stat.S_IROTH)\n    for item in glob.glob(\"%s/*\" % baseline_casedocs):\n        os.chmod(item, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)\n\n    for item in glob.glob(os.path.join(test_dir, \"user_nl*\")):\n        preexisting_baseline = os.path.join(baseline_dir, os.path.basename(item))\n        if (os.path.exists(preexisting_baseline)):\n            os.remove(preexisting_baseline)\n\n        shutil.copy2(item, baseline_dir)\n        os.chmod(preexisting_baseline, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP)\n\ndef case_cmpgen_namelists(case, compare=False, generate=False, compare_name=None, generate_name=None, baseline_root=None, logfile_name=\"TestStatus.log\"):\n    expect(case.get_value(\"TEST\"), \"Only makes sense to run this for a test case\")\n\n    caseroot, casebaseid = case.get_value(\"CASEROOT\"), case.get_value(\"CASEBASEID\")\n\n    if not compare:\n        compare = case.get_value(\"COMPARE_BASELINE\")\n    if not generate:\n        generate = case.get_value(\"GENERATE_BASELINE\")\n\n    if not compare and not generate:\n        logging.info(\"Nothing to do\")\n        return True\n\n    # create namelists for case if they haven't been already\n    casedocs = os.path.join(caseroot, \"CaseDocs\")\n    if not os.path.exists(os.path.join(casedocs, \"drv_in\")):\n        create_namelists(case)\n\n    test_name = casebaseid if casebaseid is not None else case.get_value(\"CASE\")\n    with TestStatus(test_dir=caseroot, test_name=test_name) as ts:\n        try:\n            # Inside this try are where we catch non-fatal errors, IE errors involving\n            # baseline operations which may not directly impact the functioning of the viability of this case\n            if compare and not compare_name:\n                compare_name = case.get_value(\"BASELINE_NAME_CMP\")\n                compare_name = get_current_branch() if compare_name is None else compare_name\n                expect(compare_name, \"Was asked to do baseline compare but unable to determine baseline name\")\n                logging.info(\"Comparing namelists with baselines '%s'\" % compare_name)\n            if generate and not generate_name:\n                generate_name = case.get_value(\"BASELINE_NAME_GEN\")\n                generate_name = get_current_branch() if generate_name is None else generate_name\n                expect(generate_name, \"Was asked to do baseline generation but unable to determine baseline name\")\n                logging.info(\"Generating namelists to baselines '%s'\" % generate_name)\n\n            success = True\n            output = \"\"\n            if compare:\n                success, output = _do_full_nl_comp(case, test_name, compare_name, baseline_root)\n            if generate:\n                _do_full_nl_gen(case, test_name, generate_name, baseline_root)\n        except:\n            ts.set_status(NAMELIST_PHASE, TEST_FAIL_STATUS)\n            success = False\n            warn = \"Exception during namelist operations:\\n%s\\n%s\" % (sys.exc_info()[1], traceback.format_exc())\n            output += warn\n            logging.warning(warn)\n        finally:\n            ts.set_status(NAMELIST_PHASE, TEST_PASS_STATUS if success else TEST_FAIL_STATUS)\n            append_status(output, caseroot=caseroot, sfile=logfile_name)\n\n        return success\n\n", "path": "utils/python/CIME/case_cmpgen_namelists.py"}]}