Skip to content

Commit

Permalink
minor: pep8 cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Nov 5, 2012
1 parent 1612912 commit d67a965
Showing 1 changed file with 24 additions and 20 deletions.
44 changes: 24 additions & 20 deletions moa/plugin/system/extraCommands.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Copyright 2009-2011 Mark Fiers
# The New Zealand Institute for Plant & Food Research
#
#
# This file is part of Moa - http://github.com/mfiers/Moa
#
#
# Licensed under the GPL license (see 'COPYING')
#
#
"""
**extraCommands** - Pre & Post commands
---------------------------------------
Expand All @@ -19,26 +19,26 @@

from moa.sysConf import sysConf


def hook_prepare_3():
job = sysConf['job']

job.template.parameters.precommand = {
'category' : 'advanced',
'optional' : True,
'help' : 'A single command to be executed before the main run' + \
'starts',
'recursive' : False,
'type' : 'string'
}

'category': 'advanced',
'optional': True,
'help': 'A single command to be executed before the main run' +
'starts',
'recursive': False,
'type': 'string'}

job.template.parameters.postcommand = {
'category' : 'advanced',
'optional' : True,
'help' : 'A single command to be executed after the main run ' + \
'starts',
'recursive' : False,
'type' : 'string'
}
'category': 'advanced',
'optional': True,
'help': 'A single command to be executed after the main run ' +
'starts',
'recursive': False,
'type': 'string'}


@moa.args.needsJob
@moa.args.command
Expand All @@ -54,20 +54,22 @@ def postcommand(job, args):
moa.ui.message("%s" % postcommand)
executeExtraCommand(postcommand, job)


@moa.args.needsJob
@moa.args.command
def precommand(job, args):
"""
Execute 'precommand'
"""
job = sysConf.job
renderedConf = job.conf.render()
renderedConf = job.conf.render()
precommand = renderedConf.get('precommand', '')
if precommand:
moa.ui.message("Executing precommand")
moa.ui.message("%s" % precommand)
executeExtraCommand(precommand, job)


def executeExtraCommand(command, job):
jobData = job.conf
for k in job.conf.keys():
Expand All @@ -77,10 +79,11 @@ def executeExtraCommand(command, job):
elif isinstance(v, dict):
continue
else:
os.putenv(k, str(v))
os.putenv(k, str(v))
template = jinja2.Template(command)
os.system(template.render(jobData))


def hook_preRun():
"""
If defined, execute the precommand
Expand All @@ -91,6 +94,7 @@ def hook_preRun():
l.debug("Executing precommand %s" % precommand)
executeExtraCommand(precommand, job)


def hook_postRun():
"""
If defined, execute the postCommand
Expand Down

0 comments on commit d67a965

Please sign in to comment.