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

Updated new script generation

* Added error handling for interpolation of configuration values
* Changed command line error to use logging interface
* Reduced verbosity of template defaulting
parent ff1e4c60
Branches attic/experiment_setup/16
No related tags found
No related merge requests found
......@@ -10,7 +10,7 @@ import stat
import StringIO
import sys
from configobj import ConfigObj
from configobj import ConfigObj, InterpolationError
from jinja2 import Environment, FileSystemLoader
#
......@@ -22,6 +22,7 @@ que_lib_dir = 'standard_queue_settings'
default_name = 'DEFAULT'
logging.basicConfig(format='%(levelname)s: %(message)s')
logging.addLevelName(logging.INFO, 'Note')
logging.addLevelName(logging.WARNING, 'Hey')
logging.addLevelName(logging.ERROR, 'Oops')
logging.addLevelName(logging.CRITICAL, 'Sorry')
......@@ -58,7 +59,7 @@ def get_template_name(experiment_kind, job_id):
'''Determine script template, taking system default if type is unsupported.'''
run_template_name = os.path.join(exp_lib_dir, experiment_kind+'.'+job_id+'.tmpl')
if not os.path.exists(run_template_name):
logging.warning("no %s template for '%s', using default", job_id, experiment_kind)
logging.info("no %s template for '%s', using default", job_id, experiment_kind)
run_template_name = os.path.join(exp_lib_dir, default_name+'.'+job_id+'.tmpl')
return run_template_name
......@@ -139,11 +140,14 @@ def split_jobs(config):
# Check command line
if len(sys.argv) < 2:
sys.stderr.write('Oops: invalid number of parameters!\n' +
'Usage: '+sys.argv[0]+' experiment_config_name\n')
logging.error('invalid number of parameters\n' +
'Usage: '+sys.argv[0]+' experiment_config_name')
sys.exit(1)
experiment_config_name = sys.argv[1]
if not os.path.exists(experiment_config_name):
logging.error("config file '{0}' does not exist".format(experiment_config_name))
sys.exit(1)
# Read and store configuration info from input and experiments' library
# Store environment as default for control settings, then add config from files
......@@ -196,7 +200,11 @@ config_lines.seek(0)
config = ConfigObj(config_lines, interpolation='template')
def eval_key(section, key):
section[key] = section[key]
try:
section[key] = section[key]
except InterpolationError as error:
logging.error("{0} while reading key '{1}'".format(error.message[:-1], key))
sys.exit(2)
config.walk(eval_key)
......
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