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

Changed script generator to allow a path for config files and templates...

Changed script generator to allow a path for config files and templates (MKEXP_PATH); directories are separated by colon.
parent aa541d51
No related branches found
No related tags found
No related merge requests found
......@@ -36,7 +36,7 @@ class ExpConfig(ConfigObj):
# Class constructor
def __init__(self, experiment_config_name, extra_dict={}):
def __init__(self, experiment_config_name, extra_dict={}, config_roots=['']):
'''Read experiment config to get basic settings
TODO: probably nicer if default experiment is given as argument
......@@ -59,6 +59,18 @@ class ExpConfig(ConfigObj):
config['jobs'][subjob] = subconfig.dict()
del config['jobs'][subjobs]
def get_config_name(lib_name, base_name):
'''Cycle through config path until a match is found.
Return simple path otherwise'''
config_name = os.path.join(lib_name, base_name)
for config_root in config_roots:
tentative_name = os.path.join(config_root, config_name)
if os.path.exists(tentative_name):
config_name = tentative_name
break
return config_name
#
# Method body
#
......@@ -94,15 +106,15 @@ class ExpConfig(ConfigObj):
# Read experiment settings from library (default and type specific)
lib_config_name = os.path.join(ExpConfig.exp_lib_dir,
ExpConfig.default_name+'.config')
lib_config_name = get_config_name(ExpConfig.exp_lib_dir,
ExpConfig.default_name+'.config')
pre_config.merge(ConfigObj(lib_config_name, interpolation=False))
split_jobs(pre_config)
config_versions.append(pre_config['VERSION_'])
del pre_config['VERSION_']
lib_config_name = os.path.join(ExpConfig.exp_lib_dir,
experiment_type+'.config')
lib_config_name = get_config_name(ExpConfig.exp_lib_dir,
experiment_type+'.config')
if os.path.exists(lib_config_name):
pre_config.merge(ConfigObj(lib_config_name, interpolation=False))
split_jobs(pre_config)
......@@ -114,8 +126,8 @@ class ExpConfig(ConfigObj):
# Read host environment settings from library
lib_config_name = os.path.join(ExpConfig.env_lib_dir,
environment+'.config')
lib_config_name = get_config_name(ExpConfig.env_lib_dir,
environment+'.config')
if os.path.exists(lib_config_name):
pre_config.merge(ConfigObj(lib_config_name, interpolation=False))
......
......@@ -12,7 +12,7 @@ import StringIO
import sys
from configobj import ConfigObj
from jinja2 import Environment, FileSystemLoader
from jinja2 import Environment, ChoiceLoader, FileSystemLoader
from expconfig import ExpConfig, ExpConfigError
import feedback
......@@ -21,11 +21,11 @@ import feedback
# Basic settings
#
config_root = os.environ.get('MKEXP_ROOT', '.')
config_roots = os.environ.get('MKEXP_PATH', '').split(':')
# Setup templating environment
template_env = Environment(
loader = FileSystemLoader('.'),
loader = ChoiceLoader(map(FileSystemLoader, config_roots)),
variable_start_string = '%{',
variable_end_string = '}',
line_statement_prefix = '#%',
......@@ -183,7 +183,7 @@ if invalid_args:
extra_dict = dict(map(lambda x: x.split('=', 1), sys.argv))
extra_dict.update(mkexp_input='Generated by $$Id$$')
try:
config = ExpConfig(experiment_config_name, extra_dict)
config = ExpConfig(experiment_config_name, extra_dict, config_roots)
except ExpConfigError as error:
feedback.die(error.message, 2)
......
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