Skip to content

Commit

Permalink
Add read-only mode to Case objects.
Browse files Browse the repository at this point in the history
This commit prohibits modification of the env files outside of `with`
blocks that use `Case` as a context manager.

Passes `scripts_regression_tests`.
  • Loading branch information
quantheory committed Jul 13, 2016
1 parent f84aebb commit d7ae79b
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 174 deletions.
4 changes: 2 additions & 2 deletions cime_config/acme/machines/template.lt_archive
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def _main_func(description):
sys.exit(1 if test_results.failed > 0 else 0)

caseroot = parse_command_line(sys.argv, description)
with Case(caseroot) as case:
success = case_lt_archive(case)
case = Case(caseroot)
success = case_lt_archive(case)

sys.exit(0 if success else 1)

Expand Down
4 changes: 2 additions & 2 deletions cime_config/cesm/machines/template.lt_archive
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def _main_func(description):
sys.exit(1 if test_results.failed > 0 else 0)

caseroot = parse_command_line(sys.argv, description)
with Case(caseroot) as case:
success = case_lt_archive(case)
case = Case(caseroot)
success = case_lt_archive(case)

sys.exit(0 if success else 1)

Expand Down
18 changes: 10 additions & 8 deletions driver_cpl/cime_config/buildexe
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@ def _main_func():

logger.info("Building a single executable version of target coupled model")

with Case(caseroot) as case:
casetools = case.get_value("CASETOOLS")
cimeroot = case.get_value("CIMEROOT")
exeroot = case.get_value("EXEROOT")
gmake = case.get_value("GMAKE")
gmake_j = case.get_value("GMAKE_J")
model = case.get_value("MODEL")
os.environ["PIO_VERSION"] = str(case.get_value("PIO_VERSION"))
case = Case(caseroot)

casetools = case.get_value("CASETOOLS")
cimeroot = case.get_value("CIMEROOT")
exeroot = case.get_value("EXEROOT")
gmake = case.get_value("GMAKE")
gmake_j = case.get_value("GMAKE_J")
model = case.get_value("MODEL")

os.environ["PIO_VERSION"] = str(case.get_value("PIO_VERSION"))

with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.drv") + "\n")
Expand Down
70 changes: 36 additions & 34 deletions driver_cpl/cime_config/buildnml
Original file line number Diff line number Diff line change
Expand Up @@ -23,40 +23,42 @@ def _main_func():

caseroot = parse_input(sys.argv)

with Case(caseroot) as case:
cimeroot = case.get_value("CIMEROOT")
caseroot = case.get_value("CASEROOT")
casebuild = case.get_value("CASEBUILD")
rundir = case.get_value("RUNDIR")
grid = case.get_value("GRID")
atm_grid = case.get_value("ATM_GRID")
lnd_grid = case.get_value("LND_GRID")
ocn_grid = case.get_value("OCN_GRID")
rof_grid = case.get_value("ROF_GRID")
wav_grid = case.get_value("WAV_GRID")
comp_atm = case.get_value("COMP_ATM")
pio_version = case.get_value("PIO_VERSION")

confdir = os.path.join(casebuild, "cplconf")
if not os.path.isdir(confdir):
os.makedirs(confdir)

# create cplconf/namelist
infile_text = ""
if comp_atm == 'cam':
# *** FIXME - this is confusing!!!***
# cam is actually changing the driver namelist settings
cam_config_opts = case.get_value("CAM_CONFIG_OPTS")
if "adiabatic" in cam_config_opts:
infile_text = "atm_adiabatic = .true."
if "ideal" in cam_config_opts:
infile_text = "atm_ideal_phys = .true."
if "aquaplanet" in cam_config_opts:
infile_text = "aqua_planet = .true. \n aqua_planet_sst = 1"

user_nl_file = os.path.join(caseroot, "user_nl_cpl")
namelist_infile = os.path.join(confdir, "namelist")
create_namelist_infile(case, user_nl_file, namelist_infile, infile_text)
case = Case(caseroot)

cimeroot = case.get_value("CIMEROOT")
caseroot = case.get_value("CASEROOT")
casebuild = case.get_value("CASEBUILD")
rundir = case.get_value("RUNDIR")
grid = case.get_value("GRID")
atm_grid = case.get_value("ATM_GRID")
lnd_grid = case.get_value("LND_GRID")
ocn_grid = case.get_value("OCN_GRID")
rof_grid = case.get_value("ROF_GRID")
wav_grid = case.get_value("WAV_GRID")
comp_atm = case.get_value("COMP_ATM")
pio_version = case.get_value("PIO_VERSION")

confdir = os.path.join(casebuild, "cplconf")
if not os.path.isdir(confdir):
os.makedirs(confdir)

# create cplconf/namelist

infile_text = ""
if comp_atm == 'cam':
# *** FIXME - this is confusing!!!***
# cam is actually changing the driver namelist settings
cam_config_opts = case.get_value("CAM_CONFIG_OPTS")
if "adiabatic" in cam_config_opts:
infile_text = "atm_adiabatic = .true."
if "ideal" in cam_config_opts:
infile_text = "atm_ideal_phys = .true."
if "aquaplanet" in cam_config_opts:
infile_text = "aqua_planet = .true. \n aqua_planet_sst = 1"

user_nl_file = os.path.join(caseroot, "user_nl_cpl")
namelist_infile = os.path.join(confdir, "namelist")
create_namelist_infile(case, user_nl_file, namelist_infile, infile_text)

# call build-namelist

Expand Down
12 changes: 6 additions & 6 deletions scripts/Tools/check_input_data
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ def _main_func(description):

svn_loc, input_data_root, data_list_dir, download = parse_command_line(sys.argv, description)

with Case() as case:
sys.exit(0 if check_input_data(case,
svn_loc=svn_loc,
input_data_root=input_data_root,
data_list_dir=data_list_dir,
download=download) else 1)
case = Case()
sys.exit(0 if check_input_data(case,
svn_loc=svn_loc,
input_data_root=input_data_root,
data_list_dir=data_list_dir,
download=download) else 1)

###############################################################################

Expand Down
98 changes: 49 additions & 49 deletions scripts/Tools/getTiming
Original file line number Diff line number Diff line change
Expand Up @@ -120,55 +120,55 @@ class TimingParser:


def getTiming(self):
with Case(self.caseroot) as case:
components=case.get_value("COMP_CLASSES").split(',')
components[components.index("DRV")]="CPL"
for s in components:
self.models[s] = getTimingInfo(s)
atm = self.models['ATM']
lnd = self.models['LND']
rof = self.models['ROF']
wav = self.models['WAV']
ice = self.models['ICE']
ocn = self.models['OCN']
glc = self.models['GLC']
cpl = self.models['CPL']
cime_model = case.get_value("MODEL")
caseid = case.get_value("CASE")
mach = case.get_value("MACH")
user = case.get_value("USER")
continue_run = case.get_value("CONTINUE_RUN")
rundir = case.get_value("RUNDIR")
run_type = case.get_value("RUN_TYPE")
ncpl_base_period = case.get_value("NCPL_BASE_PERIOD")
atm_ncpl = case.get_value("ATM_NCPL")
ocn_ncpl = case.get_value("OCN_NCPL")
ccsm_compset = case.get_value("CCSM_COMPSET")
if ccsm_compset is None:
ccsm_compset = ""
grid = case.get_value("GRID")
run_type = case.get_value("RUN_TYPE")
stop_option = case.get_value("STOP_OPTION")
stop_n = case.get_value("STOP_N")
cost_pes = case.get_value("COST_PES")
totalpes = case.get_value("TOTALPES")
pes_per_node = case.get_value("PES_PER_NODE")

if cost_pes > 0:
pecost = cost_pes
else:
pecost = totalpes

for m in self.models.values():
for key in ["NTASKS", "ROOTPE", "PSTRID", "NTHRDS", "NINST"]:
if key == "NINST" and m.name == "CPL":
m.ninst = 1
else:
setattr(m, key.lower(),
int(case.get_value("%s_%s" % (key, m.name))))

m.comp = case.get_value("COMP_%s" % (m.name))
m.pemax = m.rootpe + m.ntasks * m.pstrid - 1
case = Case(self.caseroot)
components=case.get_value("COMP_CLASSES").split(',')
components[components.index("DRV")]="CPL"
for s in components:
self.models[s] = getTimingInfo(s)
atm = self.models['ATM']
lnd = self.models['LND']
rof = self.models['ROF']
wav = self.models['WAV']
ice = self.models['ICE']
ocn = self.models['OCN']
glc = self.models['GLC']
cpl = self.models['CPL']
cime_model = case.get_value("MODEL")
caseid = case.get_value("CASE")
mach = case.get_value("MACH")
user = case.get_value("USER")
continue_run = case.get_value("CONTINUE_RUN")
rundir = case.get_value("RUNDIR")
run_type = case.get_value("RUN_TYPE")
ncpl_base_period = case.get_value("NCPL_BASE_PERIOD")
atm_ncpl = case.get_value("ATM_NCPL")
ocn_ncpl = case.get_value("OCN_NCPL")
ccsm_compset = case.get_value("CCSM_COMPSET")
if ccsm_compset is None:
ccsm_compset = ""
grid = case.get_value("GRID")
run_type = case.get_value("RUN_TYPE")
stop_option = case.get_value("STOP_OPTION")
stop_n = case.get_value("STOP_N")
cost_pes = case.get_value("COST_PES")
totalpes = case.get_value("TOTALPES")
pes_per_node = case.get_value("PES_PER_NODE")

if cost_pes > 0:
pecost = cost_pes
else:
pecost = totalpes

for m in self.models.values():
for key in ["NTASKS", "ROOTPE", "PSTRID", "NTHRDS", "NINST"]:
if key == "NINST" and m.name == "CPL":
m.ninst = 1
else:
setattr(m, key.lower(),
int(case.get_value("%s_%s" % (key, m.name))))

m.comp = case.get_value("COMP_%s" % (m.name))
m.pemax = m.rootpe + m.ntasks * m.pstrid - 1

now = datetime.datetime.ctime(datetime.datetime.now())
inittype = "FALSE"
Expand Down
38 changes: 18 additions & 20 deletions scripts/Tools/xmlquery
Original file line number Diff line number Diff line change
Expand Up @@ -105,26 +105,24 @@ def xmlquery(caseroot, args, listofattributes=[] , subgroup=None, noecho=False,
True
"""
# Initialize case ; read in all xml files from caseroot
with Case(caseroot) as case:
values = []
results = [] # List of formatted strings containing the search results

if(listofattributes and len(listofattributes) >= 1):

for xmlattr in listofattributes:
# type_str = case.get_type_info(xmlattr)
logger.debug("Searching for %s", xmlattr)
attribute_hits = case.get_values(xmlattr, resolved=args.resolve,
subgroup=subgroup)
results += attribute_hits

elif (args.listall):
logger.warning("Retrieving all values.")
results = case.get_values(None, resolved=args.resolve,
subgroup=subgroup)
else:
logger.warning("No attributes (%s) or listall option",
listofattributes)
case = Case(caseroot)
values = []
results = [] # List of formatted strings containing the search results

if(listofattributes and len(listofattributes) >= 1):

for xmlattr in listofattributes:
# type_str = case.get_type_info(xmlattr)
logger.debug("Searching for %s", xmlattr)
attribute_hits = case.get_values(xmlattr, resolved=args.resolve, subgroup=subgroup)

results += attribute_hits

elif (args.listall):
logger.warning("Retrieving all values.")
results = case.get_values(None, resolved=args.resolve, subgroup=subgroup)
else:
logger.warning("No attributes (%s) or listall option" , listofattributes)

# Formatting of return strings
if ( len(results) > 0) :
Expand Down
58 changes: 29 additions & 29 deletions utils/python/CIME/buildlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,58 +43,58 @@ def build_data_lib(argv, compclass):

caseroot, libroot, bldroot = parse_input(argv)

with Case(caseroot) as case:
case = Case(caseroot)

cimeroot = case.get_value("CIMEROOT")
cimeroot = case.get_value("CIMEROOT")

# Write directory list (Filepath)
compname = "d" + compclass
with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.%s" %compname) + "\n")
out.write(os.path.join(cimeroot, "components", "data_comps", compname) + "\n")
# Write directory list (Filepath)
compname = "d" + compclass
with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.%s" %compname) + "\n")
out.write(os.path.join(cimeroot, "components", "data_comps", compname) + "\n")

# Build the component
run_gmake(case, compclass, libroot)
# Build the component
run_gmake(case, compclass, libroot)

###############################################################################
def build_xcpl_lib(argv, compclass):
###############################################################################

caseroot, libroot, bldroot = parse_input(argv)

with Case(caseroot) as case:
case = Case(caseroot)

cimeroot = case.get_value("CIMEROOT")
cimeroot = case.get_value("CIMEROOT")

# Write directory list
compname = "x" + compclass
with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.%s", compname) + "\n")
out.write(os.path.join(cimeroot, "components", "xcpl_comps", "xshare") + "\n")
out.write(os.path.join(cimeroot, "components", "xcpl_comps",compname, "cpl") + "\n")
# Write directory list
compname = "x" + compclass
with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.%s", compname) + "\n")
out.write(os.path.join(cimeroot, "components", "xcpl_comps", "xshare") + "\n")
out.write(os.path.join(cimeroot, "components", "xcpl_comps",compname, "cpl") + "\n")

# Build the component
run_gmake(case, compclass, libroot)
# Build the component
run_gmake(case, compclass, libroot)

###############################################################################
def build_stub_lib(argv, compclass):
###############################################################################

caseroot, libroot, bldroot = parse_input(argv)

with Case(caseroot) as case:
case = Case(caseroot)

cimeroot = case.get_value("CIMEROOT")
cimeroot = case.get_value("CIMEROOT")

# Write directory list
compname = "s" + compclass
with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.%s", compname) + "\n")
out.write(os.path.join(cimeroot, "components", "stub_comps", "xshare") + "\n")
out.write(os.path.join(cimeroot, "components", "stub_comps",compname, "cpl") + "\n")
# Write directory list
compname = "s" + compclass
with open('Filepath', 'w') as out:
out.write(os.path.join(caseroot, "SourceMods", "src.%s", compname) + "\n")
out.write(os.path.join(cimeroot, "components", "stub_comps", "xshare") + "\n")
out.write(os.path.join(cimeroot, "components", "stub_comps",compname, "cpl") + "\n")

# Build the component
run_gmake(case, compclass, libroot)
# Build the component
run_gmake(case, compclass, libroot)

###############################################################################
def run_gmake(case, compclass, libroot, libname="", user_cppdefs=""):
Expand Down
Loading

0 comments on commit d7ae79b

Please sign in to comment.