def _case_two_custom_prerun_action(self): dout_s_root = self._case1.get_value("DOUT_S_ROOT") rest_root = os.path.abspath(os.path.join(dout_s_root,"rest")) restart_list = ls_sorted_by_mtime(rest_root) expect(len(restart_list) >= 1, "No restart files found in {}".format(rest_root)) restore_from_archive(self._case, rest_dir= os.path.join(rest_root, restart_list[0]))
def restore_from_archive(self, rest_dir=None, dout_s_root=None, rundir=None): ############################################################################### """ Take archived restart files and load them into current case. Use rest_dir if provided otherwise use most recent restore_from_archive is a member of Class Case """ if dout_s_root is None: dout_s_root = self.get_value("DOUT_S_ROOT") if rundir is None: rundir = self.get_value("RUNDIR") if rest_dir is not None: if not os.path.isabs(rest_dir): rest_dir = os.path.join(dout_s_root, "rest", rest_dir) else: rest_dir = os.path.join( dout_s_root, "rest", ls_sorted_by_mtime(os.path.join(dout_s_root, "rest"))[-1]) logger.info("Restoring restart from {}".format(rest_dir)) for item in glob.glob("{}/*".format(rest_dir)): base = os.path.basename(item) dst = os.path.join(rundir, base) if os.path.exists(dst): os.remove(dst) logger.info("Restoring {} from {} to {}".format( item, rest_dir, rundir)) safe_copy(item, rundir)
def restore_from_archive(self, rest_dir=None, dout_s_root=None, rundir=None): ############################################################################### """ Take archived restart files and load them into current case. Use rest_dir if provided otherwise use most recent restore_from_archive is a member of Class Case """ if dout_s_root is None: dout_s_root = self.get_value("DOUT_S_ROOT") if rundir is None: rundir = self.get_value("RUNDIR") if rest_dir is not None: if not os.path.isabs(rest_dir): rest_dir = os.path.join(dout_s_root, "rest", rest_dir) else: rest_dir = os.path.join(dout_s_root, "rest", ls_sorted_by_mtime(os.path.join(dout_s_root, "rest"))[-1]) logger.info("Restoring restart from {}".format(rest_dir)) for item in glob.glob("{}/*".format(rest_dir)): base = os.path.basename(item) dst = os.path.join(rundir, base) if os.path.exists(dst): os.remove(dst) logger.info("Restoring {} from {} to {}".format(item, rest_dir, rundir)) safe_copy(item, rundir)
def _case_one_custom_postrun_action(self): self._case.case_st_archive() # Since preview namelist is run before _case_two_prerun_action, we need to do this here. dout_s_root = self._case1.get_value("DOUT_S_ROOT") restart_list = ls_sorted_by_mtime(os.path.join(dout_s_root,"rest")) logger.info("Restart directory list is {}".format(restart_list)) expect(len(restart_list) >=2,"Expected at least two restart directories") # Get the older of the two restart directories self._case2.restore_from_archive(rest_dir=os.path.abspath( os.path.join(dout_s_root, "rest", restart_list[0])))
def _case_one_custom_postrun_action(self): self._case.case_st_archive() # Since preview namelist is run before _case_two_prerun_action, we need to do this here. dout_s_root = self._case1.get_value("DOUT_S_ROOT") restart_list = ls_sorted_by_mtime(os.path.join(dout_s_root,"rest")) logger.info("Restart directory list is {}".format(restart_list)) expect(len(restart_list) >=2,"Expected at least two restart directories") # Get the older of the two restart directories self._case2.restore_from_archive(rest_dir=os.path.abspath( os.path.join(dout_s_root, "rest", restart_list[0])))
def restore_from_archive(case, rest_dir=None): ############################################################################### """ Take archived restart files and load them into current case. Use rest_dir if provided otherwise use most recent """ dout_sr = case.get_value("DOUT_S_ROOT") rundir = case.get_value("RUNDIR") if rest_dir is not None: if not os.path.isabs(rest_dir): rest_dir = os.path.join(dout_sr, "rest", rest_dir) else: rest_dir = ls_sorted_by_mtime(os.path.join(dout_sr, "rest"))[-1] logger.info("Restoring from {} to {}".format(rest_dir, rundir)) for item in glob.glob("{}/*".format(rest_dir)): base = os.path.basename(item) dst = os.path.join(rundir, base) if os.path.exists(dst): os.remove(dst) shutil.copy(item, rundir)
archive_file_fn) ############################################################################### def restore_from_archive(case, rest_dir=None): ############################################################################### """ Take archived restart files and load them into current case. Use rest_dir if provided otherwise use most recent """ dout_sr = case.get_value("DOUT_S_ROOT") rundir = case.get_value("RUNDIR") if rest_dir is not None: if not os.path.isabs(rest_dir): rest_dir = os.path.join(dout_sr, "rest", rest_dir) else: rest_dir = ls_sorted_by_mtime(os.path.join(dout_sr, "rest"))[-1] logger.info("Restoring from {} to {}".format(rest_dir, rundir)) for item in glob.glob("{}/*".format(rest_dir)): base = os.path.basename(item) dst = os.path.join(rundir, base) if os.path.exists(dst): os.remove(dst) shutil.copy(item, rundir) ############################################################################### def archive_last_restarts(case, archive_restdir, last_date=None,