Skip to content

Commit

Permalink
Better docs for moa set. Value check for system configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Oct 23, 2012
1 parent 9a0f5e0 commit 9b3341c
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions lib/python/moa/plugin/system/configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,6 @@ def unset(job, args):
@moa.args.addFlag('-s', '--system', help='store this a ' +
'system configuration variable')
@moa.args.forceable
@moa.args.needsJob
@moa.args.command
def set(job, args):
"""Set one or more variables
Expand All @@ -236,17 +235,19 @@ def set(job, args):
'moa set PARAMETER_NAME', in which case Moa will prompt the user
enter a value - circumventing problems with bash interpretation.
if -s is specified, the variable is stored as a system
configuration variable in the YAML formatted::
Note: without -s, moa needs to be executed from within a Moa job
~/.config/moa/config
System configuration
####################
Please, use this with care!
By specifying `-s` or `--system`, the variable is stored as a
system configuration variable in the YAML formatted
`~/.config/moa/config`. Please, use this with care!
Note that dots in the key name are interpreted as nested levels,
so, running::
The dots in the key name are interpreted as nested levels, so,
running::
moa set -s plugins.job.completion.enabled=false
moa set -s plugins.job.completion.enabled=false
will result in the following section added on top of the YAML::
Expand All @@ -269,9 +270,13 @@ def set(job, args):
completion:
enabled: false
someting: else
"""

#see if we need to query the user for input somehwere
if not args.system:
moa.util.moaDirOrExit()

new_pars = []
for a in args.parameter:

Expand All @@ -285,18 +290,28 @@ def set(job, args):
job.conf[key] = val

new_pars.append((key, val))
moa.ui.message('setting "%s" to "%s"' % (a, " ".join(val.split())))
moa.ui.message('setting "%s" to "%s"' % (key, " ".join(val.split())))

if args.system:

sys_pars = dict(new_pars)

valCheck = {
'true': True,
'false': False}

def _dictify(d):
for k in list(d.keys()):
if '.' in k:

na, nb = k.split('.', 1)
d[na] = _dictify({nb: d[k]})
del d[k]
else:
val = d[k]
if val.lower() in valCheck:
val = valCheck[val.lower()]
d[k] = val
return d

userConf = sysConf.getUser()
Expand Down

0 comments on commit 9b3341c

Please sign in to comment.