def fill_save_tpl(cfg, tpl_str, tpl_vals_dict, tpl_name, filled_tpl_name, print_info=True): """ use the dictionary to make the file name and filled template. Then save the file. @param cfg: configuration for run @param tpl_str: the string to be filled to make the filled tpl file @param tpl_vals_dict: dictionary of tpl keys and vals @param tpl_name: the cfg key for the template file name @param filled_tpl_name: the cfg key for the filled template file name @param print_info: print to standard out when a file is printed """ try: filled_tpl_str = tpl_str.format(**tpl_vals_dict) except KeyError as e: raise KeyError( "Key '{}' not found in the configuration but required for template file: {}" "".format(e.message, tpl_name)) try: filled_fname_str = filled_tpl_name.format(**tpl_vals_dict) except KeyError as e: raise KeyError( "Key '{}' not found in the configuration but required for filled template file name: {}" "".format(e.message, filled_tpl_name)) tpl_vals_dict[NEW_FNAME] = create_out_fname(filled_fname_str, base_dir=cfg[OUT_DIR]) str_to_file(filled_tpl_str, tpl_vals_dict[NEW_FNAME], print_info=print_info)
def write_submit(tgt_dir, sub_tpl_base, sub_tpl_line, step, overwrite=False): """ Uses the given templates and step number to write a submit script to the given target file location. :param sub_tpl_base: The base template. :param sub_tpl_line: The line template. :param step: The step number. :param tgt_dir: The target directory. :param overwrite: Whether to allow overwrites. """ sub_file = os.path.join(tgt_dir, STEP_SUBMIT_FNAME.format(step)) if allow_write(sub_file, overwrite): wham_fill = fill_submit_wham(sub_tpl_base, sub_tpl_line, step, use_part=False) str_to_file(wham_fill, sub_file)