fn replace_placeholders(program: &mut ProgramDefinition) {
    let date = format_rfc3339(std::time::SystemTime::now()).to_string();
    let submit_dir = PathBuf::from(
        program.env[&BString::from(HQ_SUBMIT_DIR)]
            .to_os_str()
            .unwrap_or_default(),
    );

    let mut placeholder_map = HashMap::new();
    placeholder_map.insert(
        "%{JOB_ID}",
        program.env[&BString::from(HQ_JOB_ID)].to_string(),
    );
    placeholder_map.insert(
        "%{TASK_ID}",
        program.env[&BString::from(HQ_TASK_ID)].to_string(),
    );
    placeholder_map.insert(
        "%{SUBMIT_DIR}",
        program.env[&BString::from(HQ_SUBMIT_DIR)].to_string(),
    );
    placeholder_map.insert("%{DATE}", date);

    let replace = |replacement_map: &HashMap<&str, String>, path: &PathBuf| -> PathBuf {
        let mut result: String = path.to_str().unwrap().into();
        for (placeholder, replacement) in replacement_map.iter() {
            result = result.replace(placeholder, replacement);
        }
        result.into()
    };

    // Replace CWD
    program.cwd = program
        .cwd
        .as_ref()
        .map(|cwd| submit_dir.join(replace(&placeholder_map, cwd)))
        .or_else(|| Some(std::env::current_dir().unwrap()));

    // Replace STDOUT and STDERR
    placeholder_map.insert(
        "%{CWD}",
        program.cwd.as_ref().unwrap().to_str().unwrap().to_string(),
    );

    program.stdout = program
        .stdout
        .as_ref()
        .map(|path| submit_dir.join(replace(&placeholder_map, path)));
    program.stderr = program
        .stderr
        .as_ref()
        .map(|path| submit_dir.join(replace(&placeholder_map, path)));
}
/// Replace placeholders in user-defined program attributes
Replace placeholders in user-defined program attributes
Replace placeholders in user - defined program attributes
fn replace_placeholders(program: &mut ProgramDefinition) {
    let date = format_rfc3339(std::time::SystemTime::now()).to_string();
    let submit_dir = PathBuf::from(
        program.env[&BString::from(HQ_SUBMIT_DIR)]
            .to_os_str()
            .unwrap_or_default(),
    );
    let mut placeholder_map = HashMap::new();
    placeholder_map.insert(
        "%{JOB_ID}",
        program.env[&BString::from(HQ_JOB_ID)].to_string(),
    );
    placeholder_map.insert(
        "%{TASK_ID}",
        program.env[&BString::from(HQ_TASK_ID)].to_string(),
    );
    placeholder_map.insert(
        "%{SUBMIT_DIR}",
        program.env[&BString::from(HQ_SUBMIT_DIR)].to_string(),
    );
    placeholder_map.insert("%{DATE}", date);
    let replace = |replacement_map: &HashMap<&str, String>, path: &PathBuf| -> PathBuf {
        let mut result: String = path.to_str().unwrap().into();
        for (placeholder, replacement) in replacement_map.iter() {
            result = result.replace(placeholder, replacement);
        }
        result.into()
    };
    // Replace CWD
    program.cwd = program
        .cwd
        .as_ref()
        .map(|cwd| submit_dir.join(replace(&placeholder_map, cwd)))
        .or_else(|| Some(std::env::current_dir().unwrap()));
    // Replace STDOUT and STDERR
    placeholder_map.insert(
        "%{CWD}",
        program.cwd.as_ref().unwrap().to_str().unwrap().to_string(),
    );
    program.stdout = program
        .stdout
        .as_ref()
        .map(|path| submit_dir.join(replace(&placeholder_map, path)));
    program.stderr = program
        .stderr
        .as_ref()
        .map(|path| submit_dir.join(replace(&placeholder_map, path)));
}
fn replace_placeholders ( program : & mut ProgramDefinition ) { let date = format_rfc3339 ( std :: time :: SystemTime :: now ( ) ) . to_string ( ) ; let submit_dir = PathBuf :: from ( program . env [ & BString :: from ( HQ_SUBMIT_DIR ) ] . to_os_str ( ) . unwrap_or_default ( ) , ) ; let mut placeholder_map = HashMap :: new ( ) ; placeholder_map . insert ( " " , program . env [ & BString :: from ( HQ_JOB_ID ) ] . to_string ( ) , ) ; placeholder_map . insert ( " " , program . env [ & BString :: from ( HQ_TASK_ID ) ] . to_string ( ) , ) ; placeholder_map . insert ( " " , program . env [ & BString :: from ( HQ_SUBMIT_DIR ) ] . to_string ( ) , ) ; placeholder_map . insert ( " " , date ) ; let replace = | replacement_map : & HashMap < & str , String > , path : & PathBuf | -> PathBuf { let mut result : String = path . to_str ( ) . unwrap ( ) . into ( ) ; for ( placeholder , replacement ) in replacement_map . iter ( ) { result = result . replace ( placeholder , replacement ) ; } result . into ( ) } ; // Replace CWD program . cwd = program . cwd . as_ref ( ) . map ( | cwd | submit_dir . join ( replace ( & placeholder_map , cwd ) ) ) . or_else ( | | Some ( std :: env :: current_dir ( ) . unwrap ( ) ) ) ; // Replace STDOUT and STDERR placeholder_map . insert ( " " , program . cwd . as_ref ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) , ) ; program . stdout = program . stdout . as_ref ( ) . map ( | path | submit_dir . join ( replace ( & placeholder_map , path ) ) ) ; program . stderr = program . stderr . as_ref ( ) . map ( | path | submit_dir . join ( replace ( & placeholder_map , path ) ) ) ; }
Replace placeholders in user-defined program attributes
Replace placeholders in user - defined program attributes
program
&mut ProgramDefinition
program
&mut ProgramDefinition