moa.job

class moa.job.Job(wd)

Class defining a single job

Note - in the moa system, there can be only one current job - many operations try to access the job in sysConf

>>> wd = tempfile.mkdtemp()
>>> job = Job(wd)
>>> assert(isinstance(job, Job))
>>> assert(job.template.name == 'nojob')    
checkCommands(command)

Check command, and rearrange if there are delegates.

>>> job = newTestJob('unittest')
>>> assert(job.template.commands.run.delegate == ['prepare', 'run2'])
>>> assert(job.checkCommands('run2') == ['run2'])
>>> assert(job.checkCommands('run') == ['prepare', 'run2'])
>>> assert(job.checkCommands('prepare') == ['prepare'])
Parameters:commands (list of strings) – The list of commands to check
Returns:The checked list of commands
Return type:list of strings
checkConfDir()

Check if the configuration directory exists. If not create it.

>>> job = newTestJob('unittest')
>>> confdir = os.path.join(job.wd, '.moa')
>>> assert(os.path.exists(confdir))
>>> import shutil
>>> shutil.rmtree(confdir)
>>> assert(os.path.exists(confdir) == False)
>>> job.checkConfDir()
>>> assert(os.path.exists(confdir))
defineCommands(commandparser)

Register template commands with the argparser

defineOptions(parser)

Set command line options - deferred to the backend - PER COMMAND

>>> job = newTestJob('unittest')
>>> import optparse
>>> parser = optparse.OptionParser()
>>> job.defineOptions(parser)
execute(job, args, **kwargs)

Execute command in the context of this job. Execution is alwasy deferred to the backend

#Note: Uncertain how to test verbose & silent

Parameters:
  • verbose (Boolean) – output lots of data
  • silent (Boolean) – output nothing
finishExecute()

Finish the run!

getFiles()

Return all moa files - i.e. all files crucial to this job.

hasCommand(command)

Check if this job defines a certain command

Warning

THIS METHOD DOES NOT WORK PROPERLY YET

>>> job = newTestJob('unittest')
>>> assert(job.hasCommand('run'))
>>> assert(not job.hasCommand('dummy'))
initialize()

Initialize a new job in the current wd

isMoa()

Check if this is a Moa directory - Currently, this needs to be overridden #weird; uncertain if this ever gets called

loadBackend()

load the backend

loadTemplate()

Load the template for this job, based on what configuration can be found

loadTemplateMeta()

Load the template meta data for this job, based on what configuration can be found

prepareExecute()

Give this job a chance to prepare for execution.

refreshTemplate()

Reload the template into the local .moa/template.d directory

>>> job = newTestJob('unittest')
>>> templateFile = os.path.join(job.confDir, 'template.d', 'unittest.jinja2')
>>> assert(os.path.exists(templateFile))
>>> os.unlink(templateFile)
>>> assert(not os.path.exists(templateFile))
>>> job.refreshTemplate()
>>> assert(os.path.exists(templateFile))
run_hook(hook, **kwargs)

Shortcut to run a job plugin hook

setTemplate(name, provider=None)

Set a new template for this job

>>> job = newTestJob('unittest')
>>> job.setTemplate('adhoc')
>>> afile = os.path.join(job.confDir, 'template.d', 'adhoc.mk')
>>> assert(os.path.exists(afile))
moa.job.newJob(wd, template, title, parameters=[], provider=None)

Create a new job in the wd and return the proper job object currently only makefile jobs are supported - later we’ll scan the template, and instantiate the proper job type

>>> wd = tempfile.mkdtemp()
>>> job = newJob(wd, template='blast', title='test')
>>> assert(isinstance(job, Job))
>>> assert(job.template.name == 'blast')
>>> assert(job.conf.title == 'test')
Parameters:
  • wd – Directory to create this job in, note that this directory must already exists
  • template (String) – Template name for this job
  • parameters (list of (key, value) tuples) – A list of parameters to set for this job
Return type:

instance of moa.job.Job

moa.job.newTestJob(template, title='Test job', provider=None)

for testing purposes - creates a temporary directory and uses that to instantiate a job. This function returns the job object created

>>> job = newTestJob(template = 'adhoc', title='test title')
>>> assert(isinstance(job, Job))
>>> assert(os.path.exists(job.wd))
>>> assert(job.conf.title == 'test title')
>>> assert(os.path.exists(os.path.join(job.wd, '.moa')))
>>> assert(os.path.exists(os.path.join(job.wd, '.moa', 'template')))
>>> assert(job.template.name == 'adhoc')
Returns:the created job
Return type:instance of moa.job.Job