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

Changed command line and comment handling for script generator

* Changed to use argparse library for command line handling
* Added option to set search path for standard configuration (--path)
* Added use of config file comments in namelist files
parent 5dec2bd9
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
# $Id$
#
import argparse
import os
import sys
......@@ -13,29 +14,42 @@ from feedback import die
# Basic settings
config_roots = os.environ.get('MKEXP_PATH', '').split(':')
#
# Main routine
#
# Check environment
config_roots = os.environ.get('MKEXP_PATH', '').split(':')
# Check command line
program = sys.argv.pop(0)
usage = 'Usage: ' + program + ' experiment_config_name [key=value...]'
command_line = argparse.ArgumentParser(description=
'Generate an experiment from templates and the given configuration file.')
command_line.add_argument('config', help='experiment configuration file name')
command_line.add_argument('assigns', metavar='key=value', nargs='*',
help='override configuration file settings')
command_line.add_argument('--path', '-p',
help='search path for default config and templates')
args = command_line.parse_args()
if len(sys.argv) < 1:
die('invalid number of parameters\n' + usage)
# Experiment configuration
if args.path:
config_roots = args.path.split(':')
experiment_config_name = sys.argv.pop(0)
experiment_config_name = args.config
if not os.path.exists(experiment_config_name):
die("config file '{0}' does not exist".format(experiment_config_name))
invalid_args = filter(lambda x: not x.find('=')+1, sys.argv)
# Overrides
invalid_args = filter(lambda x: not x.find('=')+1, args.assigns)
if invalid_args:
die("invalid parameters ('"+"', '".join(invalid_args)+"')\n" + usage)
die("invalid parameters ('"+"', '".join(invalid_args)+"')\n" +
command_line.format_usage())
# Read and store configuration info from input and experiments' library
# Store environment as default for control settings, then add config from files
......@@ -46,7 +60,7 @@ if os.environ.has_key('DIFF'):
try:
config = ExpConfig(experiment_config_name,
dict(map(lambda x: x.split('=', 1), sys.argv)),
dict(map(lambda x: x.split('=', 1), args.assigns)),
config_roots)
except ExpConfigError as error:
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