Skip to content

Commit

Permalink
Fixed order of plugin hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
mfiers committed Apr 5, 2011
1 parent 438eca6 commit 8251ba1
Showing 1 changed file with 72 additions and 69 deletions.
141 changes: 72 additions & 69 deletions bin/moa
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ if '-v' in sys.argv:
## Initialze the plugins
plugins = moa.plugin.PluginHandler(sysConf.getPlugins())

# Initialize the job object
wd = os.getcwd()
moa.version.fixOld(wd)


#use of cwd is deprecated
plugins.register(cwd = wd)
plugins.register(sysConf = sysConf)
plugins.register(wd = wd)

### Determine project root (if there is one)
#projectRoot = moa.project.findProjectRoot(job)
Expand Down Expand Up @@ -130,55 +121,18 @@ parser.add_option(
parser.add_option("-r", "--recursive", dest="recursive",
help="Perfom action recursively", action='store_true')

def run():

job = moa.job.Job(wd)
plugins.register(job = job)

## Aks the job & backend if they want to add to the options
job.defineOptions(parser)

## See if the plugins have anything to add to the optparse instance:
plugins.register(parser=parser)
plugins.register(commands=moaCommands)
plugins.run('defineOptions')

## Parse the options
(options, args) = parser.parse_args()

## Proper setting of verbosity - after parsing of the command line
if options.verbose:
moa.logger.setVerbose()

## Determine command to run:
command = ""
newargs = []

if len(args) > 0:
commands = [args[0]]
newargs = args[1:]
else:
commands = ['status']

originalCommand = commands[0]
plugins.register(executeCommand=commands)
plugins.register(originalCommand=commands[0])

## make sure that the options are accessible to the plugins
plugins.register(options = options, args = args)
job.options = options
job.args = args
def run(job, command):

## Ask the job if it's is ok with
## these commands (might want to change order, or insert
## the command provided (might want to change order, or insert
## stuff
commands = job.checkCommands(commands)

l.debug("Run moa commands: %s" % ",".join(commands))
l.debug("with args %s" % newargs)
execList = job.checkCommands(command)
plugins.register(executeCommand=execList)


plugins.register(newargs = newargs)
job.args = newargs
l.debug("Run moa commands: %s" % ",".join(execList))
l.debug("with args %s" % newargs)

### Start job initialization
job.prepare()
Expand All @@ -187,23 +141,24 @@ def run():
plugins.run('prepare')

#see if there is a callback to a plugin - If so call it

for command in commands:

plugins.run("preCommand")
plugins.run("pre%s" % originalCommand.capitalize())
plugins.run("preCommand")
if command not in execList:
plugins.run("pre%s" % command.capitalize())

for execNow in execList:
l.info("Executing %s" % execNow)
plugins.run("pre%s" % execNow.capitalize())

if command in moaCommands:
if moaCommands[command].has_key('call'):
l.debug("using a callback for moa %s" % command)
if execNow in moaCommands:
if moaCommands[execNow].has_key('call'):
l.debug("using a callback for moa %s" % execNow)
try:
plugins.runCallback(moaCommands[command])
plugins.runCallback(moaCommands[execNow])
rc = 0
except:
rc = -1
plugins.register(rc = rc)
plugins.run("post%s" % command.capitalize())
plugins.run("postCommand")
raise
else:
#No callback, defer this to the backend
Expand All @@ -220,21 +175,69 @@ def run():
sys.exit(0)

rc = job.execute(
command,
execNow,
verbose = options.verbose,
silent = options.silent)

plugins.register(rc = rc)
plugins.run("post%s" % originalCommand.capitalize())
plugins.run("postCommand")
plugins.run("post%s" % execNow.capitalize())

if command not in execList:
plugins.run("post%s" % command.capitalize())

plugins.run("postCommand")

plugins.run("finish")
sys.exit(rc)

## Main dispatcher
if __name__ == "__main__":
try:
run()
try:
wd = os.getcwd()

plugins.register(sysConf = sysConf)
plugins.register(wd = wd)
plugins.register(cwd = wd)

## See if the plugins have anything to add to the optparse instance:
plugins.register(parser=parser)
plugins.register(commands=moaCommands)
plugins.run('defineOptions')

job = moa.job.Job(wd)

## Aks the job & backend if they want to add to the options
job.defineOptions(parser)
plugins.register(job = job)

## Parse the options
(options, args) = parser.parse_args()

## make sure that the options are accessible to the plugins
plugins.register(options = options, args = args)
job.options = options
job.args = args

## Proper setting of verbosity - after parsing of the command line
if options.verbose:
moa.logger.setVerbose()

## Determine command to run:
if len(args) > 0:
command = args[0]
newargs = args[1:]
else:
command = 'status'
newargs

plugins.register(newargs = newargs)
job.args = newargs

plugins.register(originalCommand=command)

moa.version.fixOld(wd)
run(job, command)

except KeyboardInterrupt:
plugins.register(rc = -1)
plugins.run("postInterrupt")
Expand Down

0 comments on commit 8251ba1

Please sign in to comment.