Skip to content

Commit

Permalink
no warning if there is a template defined job title
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 21, 2012
1 parent b926915 commit 23fd704
Showing 1 changed file with 28 additions and 31 deletions.
59 changes: 28 additions & 31 deletions lib/python/moa/plugin/system/newjob.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,30 @@
# 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')
#
#
"""
**newjob** - Instantiate new jobs
---------------------------------
"""

import os

import optparse
import moa.args
import moa.job
import moa.logger
import moa.ui
from moa.sysConf import sysConf

l = moa.logger.getLogger(__name__)
#l.setLevel(moa.logger.DEBUG)

import moa.plugin
import moa.ui
import moa.args

from moa.sysConf import sysConf

#@moa.args.argument('-d', '--directory', help='directory to create the job in',
# default='.')
@moa.args.argument('parameter', nargs='*', help='arguments for this job, specify' +
@moa.args.argument('parameter', nargs='*',
help='arguments for this job, specify' +
'as KEY=VALUE without spaces')
@moa.args.argument('template', help='name of the template to use for this moa job ')
@moa.args.argument('template',
help='name of the template to use for this moa job ')
@moa.args.argument('-t', '--title', help='mandatory job title', default='')
@moa.args.forceable
@moa.args.command
Expand All @@ -43,7 +38,7 @@ def new(job, args):
for the job on the commandline using KEY=VALUE after the
template. Note: do not use spaces around the '=' sign. Use quotes
if you need spaces in variables (KEY='two values')
"""

wd = job.wd
Expand All @@ -56,12 +51,14 @@ def new(job, args):
title = args.title

template = args.template

params = []
for a in args.parameter:
if not '=' in a:
moa.ui.exitError("Need an '=' in parameter definition (problem was: '%s')" % a)
k,v = a.split('=', 1)
moa.ui.exitError("Need an '=' in parameter definition " +
"(problem was: '%s')" % a)

k, v = a.split('=', 1)
if k == 'title':
if title:
moa.ui.warn('Duplicate title defintions, using "%s"' % v)
Expand All @@ -74,18 +71,16 @@ def new(job, args):
# if not os.path.exists(fulltarget):
# moa.ui.message("Creating directory %s" % targetdir)
# os.makedirs(fulltarget)

# os.chdir(fulltarget)
# #create a new job for the target dir
# job = moa.job.Job(fulltarget)

wd = job.wd

if os.path.exists(os.path.join(wd, '.moa', 'template')) and not args.force:
moa.ui.exitError("This directory already contains a moa job\nUse -f to override")

if not title:
moa.ui.warn("Please define a title for this job")
moa.ui.exitError("This directory already contains a moa job\n" +
"Use -f to override")

originaltemplate = template
provider = None
Expand All @@ -94,31 +89,33 @@ def new(job, args):

try:
l.debug("instantiating new job")
job = moa.job.newJob(job, template=template, title = title,
job = moa.job.newJob(job, template=template, title=title,
provider=provider)
except moa.exceptions.InvalidTemplate:
moa.ui.exitError("Invalid template: %s" % template)

job.conf['title'] = title

for p in params:
k,v = p.split('=', 1)
k, v = p.split('=', 1)
job.conf[k] = v

#if no title is set - see if there is one set in the template
if not job.conf.title and job.template.parameters.title.default:
job.conf.title = job.template.parameters.title.default

if not job.conf.title:
moa.ui.warn("Please define a title for this job")

job.conf.save()

moa.ui.message('Created a "%s" job' % originaltemplate)
if title:
moa.ui.message('with title "%s"' % title)


def hook_git_finish_new():
l.debug('running git add for newjob')
job = sysConf.job
sysConf.git.commitJob(job, "Created job %s in %s" % (job.template.name, job.wd))


sysConf.git.commitJob(job,
"Created job %s in %s" % (job.template.name, job.wd))

0 comments on commit 23fd704

Please sign in to comment.