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

mkexp: added 'key' option to getexp for querying a specific config value

parent e0a24bdd
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,7 @@ Global
* Changed mkexp namelist formatting to add multi-group identifiers as comment
* Changed merge of process environment ('DEFAULT' section) to be sorted
* Added tool 'duexp' to show disk usage by the given experiment
* Added 'key' option to getexp for querying a specific config value
Release 1.0.0
=============
......
Source diff could not be displayed: it is too large. Options to address this: view the blob.
No preview for this file type
......@@ -12,6 +12,31 @@ import sys
from expconfig import ExpConfig, ExpConfigError
from feedback import setLevel, INFO, die, info
#
# Utilities
#
# Get config value, parsing dotted keys
def get_value(config, key):
sections = []
pos = key.rfind('.')
while(pos >= 0):
if key[pos-1] == '.':
key = key[0:pos-1]+key[pos:]
pos = key.rfind('.', 0, pos-1)
else:
sections.append(key[pos+1:])
key = key[0:pos]
pos = key.rfind('.')
if key:
sections.append(key)
sections.reverse()
key = sections.pop()
for section in sections:
config = config[section]
return config[key]
#
# Main routine
#
......@@ -38,6 +63,8 @@ command_line.add_argument('--readme', '-R', action='store_true',
command_line.add_argument('--verbose', '-v', action='count',
help='show all top-level settings, '
'or all settings if used twice')
command_line.add_argument('--key', '-k',
help='print value of given configuration key')
args = command_line.parse_args()
......@@ -73,6 +100,8 @@ except ExpConfigError as error:
if args.readme:
print(config['EXP_DESCRIPTION'])
elif args.key:
print(get_value(config, args.key));
elif args.verbose >= 2:
config.indent_type = ' '
config.write(sys.stdout)
......@@ -82,7 +111,6 @@ elif args.verbose == 1:
for (key, value) in items:
if not isinstance(value, dict):
print("{0}='{1}'".format(key, str(value).replace("'",'"')))
else:
print("EXP_ID='{0}'".format(config.experiment_id))
print("MODEL_DIR='{0}'".format(config['MODEL_DIR']))
......
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