diff --git a/ush/command_builder.py b/ush/command_builder.py index a3c0a41fe3..873d15a5a1 100755 --- a/ush/command_builder.py +++ b/ush/command_builder.py @@ -46,6 +46,7 @@ def __init__(self, p, logger): self.env = os.environ.copy() self.set_verbose(self.p.getstr('config', 'LOG_MET_VERBOSITY', '2')) self.cmdrunner = CommandRunner(self.p, logger=self.logger) + self.set_user_environment() self.clear() def clear(self): @@ -57,7 +58,15 @@ def clear(self): self.outdir = "" self.outfile = "" self.param = "" - + + def set_user_environment(self): + if 'user_env_vars' not in self.p.sections(): + self.p.add_section('user_env_vars') + for env_var in self.p.keys('user_env_vars'): +# if env_var in self.env: +# self.logger.warning("{} is already set in the environment. Overwriting from conf file" +# .format(env_var)) + self.add_env_var(env_var, self.p.getstr('user_env_vars', env_var)) def set_debug(self, debug): self.debug = debug @@ -132,7 +141,8 @@ def print_env_copy(self, vars): copied into terminal """ out = "" - for v in vars: + all_vars = vars + self.p.keys('user_env_vars') + for v in all_vars: if self.env[v].find('"') != -1: next = 'export '+v+'="'+self.env[v].replace('"', '\\"')+'"' else: @@ -145,6 +155,10 @@ def print_env_item(self, item): """ self.logger.debug(item+"="+self.env[item]) + def print_user_env_items(self): + for k in self.p.keys('user_env_vars'): + self.print_env_item(k) + def get_command(self): """! Builds the command to run the MET application @rtype string diff --git a/ush/compare_gridded_wrapper.py b/ush/compare_gridded_wrapper.py index 8b63bed67a..98b03ad9bc 100755 --- a/ush/compare_gridded_wrapper.py +++ b/ush/compare_gridded_wrapper.py @@ -339,10 +339,12 @@ def run_at_time_once(self, ti, v): self.add_env_var("OBS_FIELD", obs_field) self.add_env_var("INPUT_BASE", input_base) self.add_env_var("MET_VALID_HHMM", valid_time[4:8]) + self.add_env_var("FCST_TIME", str(ti.lead).zfill(3)) cmd = self.get_command() self.logger.debug("") self.logger.debug("ENVIRONMENT FOR NEXT COMMAND: ") + self.print_user_env_items() self.print_env_item("MODEL") self.print_env_item("FCST_VAR") self.print_env_item("OBS_VAR") @@ -352,14 +354,15 @@ def run_at_time_once(self, ti, v): self.print_env_item("FCST_FIELD") self.print_env_item("OBS_FIELD") self.print_env_item("INPUT_BASE") - self.print_env_item("MET_VALID_HHMM") + self.print_env_item("MET_VALID_HHMM") + self.print_env_item("FCST_TIME") self.logger.debug("") self.logger.debug("COPYABLE ENVIRONMENT FOR NEXT COMMAND: ") self.print_env_copy(["MODEL", "FCST_VAR", "OBS_VAR", "LEVEL", "OBTYPE", "CONFIG_DIR", "FCST_FIELD", "OBS_FIELD", - "INPUT_BASE", - "MET_VALID_HHMM"]) + "INPUT_BASE", "MET_VALID_HHMM", + "FCST_TIME"]) self.logger.debug("") cmd = self.get_command() if cmd is None: