Skip to content
Snippets Groups Projects
Commit 5130e7af authored by Karl-Hermann Wieners's avatar Karl-Hermann Wieners
Browse files

Added additional filters to template setup, allow user defined templates

* Added python methods list.split() and filter() to template environment for advanced template macros (file lists)
* Changed job script template search to allow local <EXP_ID>.<JOB.id>.tmpl override standard experiment templates.
parent 5450ea62
No related branches found
No related tags found
No related merge requests found
...@@ -43,16 +43,13 @@ def chmod_plus_x(file_name): ...@@ -43,16 +43,13 @@ def chmod_plus_x(file_name):
# Templates # Templates
def get_template_name(base_name): def get_template_name(base_name, dir_name=ExpConfig.exp_lib_dir):
'''Determine script template, using experiments' library path.''' '''Determine script template, using experiments' or given library path.'''
template_name = os.path.join(ExpConfig.exp_lib_dir, base_name+'.tmpl') return os.path.join(dir_name, base_name+'.tmpl')
return template_name
def get_exp_template_name(experiment_kind, job_id): def get_exp_template_name(experiment_kind, job_id, dir_name=ExpConfig.exp_lib_dir):
'''Determine script template, taking system default if type is unsupported.''' '''Determine job script template, using experiments' or given library path.'''
run_template_name = os.path.join(ExpConfig.exp_lib_dir, return get_template_name(experiment_kind+'.'+job_id, dir_name)
experiment_kind+'.'+job_id+'.tmpl')
return run_template_name
def get_script_name(base_name): def get_script_name(base_name):
'''Determine job script name.''' '''Determine job script name.'''
...@@ -233,6 +230,12 @@ template_env = Environment( ...@@ -233,6 +230,12 @@ template_env = Environment(
line_comment_prefix = '#%#' line_comment_prefix = '#%#'
) )
# Additional filters
# - There's a join but no split operation...
template_env.filters['split'] = lambda x, s: x.split(s)
# - Add list operations filter and map
template_env.filters['filter'] = lambda x, f=None: filter(f, x)
# Read and store configuration info from input and experiments' library # Read and store configuration info from input and experiments' library
# Store environment as default for control settings, then add config from files # Store environment as default for control settings, then add config from files
...@@ -342,7 +345,9 @@ for subjob, subconfig in config['jobs'].iteritems(): ...@@ -342,7 +345,9 @@ for subjob, subconfig in config['jobs'].iteritems():
# Generate job script # Generate job script
expand_template_file(job_config, expand_template_file(job_config,
( get_exp_template_name(config.experiment_kind, ( get_exp_template_name(config.experiment_id,
template_job, ''),
get_exp_template_name(config.experiment_kind,
template_job), template_job),
get_exp_template_name(ExpConfig.default_name, get_exp_template_name(ExpConfig.default_name,
template_job) ), template_job) ),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment