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: this is the function that will be called from argparse #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(job.hasCommand(‘dummy’))
-
init2
()¶ Continue initialization
-
initialize
()¶ Initialize a new job in the current wd
-
isMoa
()¶ Check if this is a Moa directory - Currently, this needs to be overridden
TODO: check if this ever gets called
-
loadBackend
()¶ load the backend
-
loadTemplate
()¶ Load the template 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') >>> templ = os.path.join(job.confDir, 'template.d', 'unittest.jinja2') >>> assert(os.path.exists(templ)) >>> os.unlink(templ) >>> assert(not os.path.exists(templ)) >>> job.refreshTemplate() >>> assert(os.path.exists(templ))
-
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('simple') >>> afile = os.path.join(job.confDir, 'template.d', 'simple.jinja2') >>> assert(os.path.exists(afile))
-
-
moa.job.
newJob
(job, 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
Parameters: - job – Job object to fill - needs only wd set.
- 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 = 'simple', 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 == ‘simple’)
Returns: the created job Return type: instance of moa.job.Job