Skip to content

Commit 5c66054

Browse files
committed
With Check
1 parent 07e4186 commit 5c66054

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

visualCaseGen/custom_widget_types/case_creator.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from ProConPy.config_var import cvars
1212
from visualCaseGen.custom_widget_types.mom6_bathy_launcher import MOM6BathyLauncher
1313
from visualCaseGen.custom_widget_types.dummy_output import DummyOutput
14-
from visualCaseGen.custom_widget_types.case_tools import xmlchange, run_case_setup, append_user_nl
14+
from visualCaseGen.custom_widget_types.case_tools import xmlchange, run_case_setup, append_user_nl, is_ccs_config_writeable
1515

1616
COMMENT = "\033[01;96m" # bold, cyan
1717
SUCCESS = "\033[1;32m" # bold, green
@@ -23,7 +23,7 @@
2323
class CaseCreator:
2424
"""The base class for CaseCreatorWidget. Here, backend functionalities are implemented."""
2525

26-
def __init__(self, cime, output=None, allow_xml_override=False, ccs_config_read_only = False):
26+
def __init__(self, cime, output=None, allow_xml_override=False):
2727
"""Initialize CaseCreator object.
2828
2929
Parameters
@@ -40,7 +40,7 @@ def __init__(self, cime, output=None, allow_xml_override=False, ccs_config_read_
4040
self._cime = cime
4141
self._out = DummyOutput() if output is None else output
4242
self._allow_xml_override = allow_xml_override
43-
self._assign_grids_through_ccs_config = not ccs_config_read_only # By default, visualCaseGen assigns grids through ccs_config, if not possible (which is possible if the user does not own the sandbox), it applies the change through xml case changes.
43+
self._assign_grids_through_ccs_config = is_ccs_config_writeable(cime) # By default, visualCaseGen assigns grids through ccs_config, if not possible (which can happen if the user does not own the sandbox), it applies the change through xml case changes.
4444

4545
def revert_launch(self, do_exec=True):
4646
"""This function is called when the case creation fails. It reverts the changes made
@@ -248,7 +248,7 @@ def _update_modelgrid_aliases(self, custom_grid_path, ocn_grid, do_exec):
248248
modelgrid_aliases_xml = modelgrid_aliases_xml.as_posix()
249249

250250
# confirm that modelgrid_aliases xml file is writeable:
251-
if not os.access(modelgrid_aliases_xml, os.W_OK):
251+
if not is_ccs_config_writeable(self.cime):
252252
raise RuntimeError(f"Cannot write to {modelgrid_aliases_xml}.")
253253

254254
# Construct the component grids string to be logged:

visualCaseGen/custom_widget_types/case_tools.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
RESET = "\033[0m"
99

1010

11+
def is_ccs_config_writeable(cime):
12+
srcroot = cime.srcroot
13+
ccs_config_root = Path(srcroot) / "ccs_config"
14+
assert (
15+
ccs_config_root.exists()
16+
), f"ccs_config_root {ccs_config_root} does not exist."
17+
modelgrid_aliases_xml = ccs_config_root / "modelgrid_aliases_nuopc.xml"
18+
return os.access(modelgrid_aliases_xml, os.W_OK)
19+
1120
def run_case_setup(do_exec, is_non_local=False, out=None):
1221
"""Run the case.setup script to set up the case instance.
1322

0 commit comments

Comments
 (0)