Skip to content

Commit

Permalink
fixed few unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 13, 2012
1 parent 89c25e8 commit aeae2e6
Showing 1 changed file with 27 additions and 32 deletions.
59 changes: 27 additions & 32 deletions lib/python/moa/template/template.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')
#
#
"""
moa.template.template
---------------------
Expand All @@ -22,21 +22,21 @@
import moa.logger as l
import moa.template


class Template(Yaco.Yaco):
"""
Template extends Yaco
Template extends Yaco
"""

def __init__(self, templateFile):
"""
Initialze the template object, which means:
* Check if the template exists, if not raise an Exception
* Load template info
>>> import moa.job
>>> job = moa.job.newTestJob(template='adhoc')
>>> job = moa.job.newTestJob(template='simple')
>>> tfile = os.path.join(job.confDir, 'template')
>>> t = Template(tfile)
>>> assert(isinstance(t, Yaco.Yaco))
Expand All @@ -51,21 +51,19 @@ def __init__(self, templateFile):
#set a few defaults to be used by each template
self.parameters = {}
self.parameters.default_command = {
'default' : 'run',
'help' : 'command to run for this template',
'optional' : True,
'private' : True,
}

'default': 'run',
'help': 'command to run for this template',
'optional': True,
'private': True}

self.parameters.jobid = {
'help' : 'Identifier for this job - Should unique in the' +
'context of this workflow',
'optional' : True,
'recursive' : False,
'type' : 'string',
'default' : 'unset'
}

'help': 'Identifier for this job - Should unique in the' +
'context of this workflow',
'optional': True,
'recursive': False,
'type': 'string',
'default': 'unset'}

self.filesets = {}

#try to load the template!!
Expand All @@ -77,17 +75,16 @@ def __init__(self, templateFile):
noTemplate = True
else:
_tempTemplate = open(self.templateFile).read().strip()
if len(_tempTemplate) < 50 and \
not "\n" in _tempTemplate:
if len(_tempTemplate) < 50 and not "\n" in _tempTemplate:
if os.access(self.templateFile, os.W_OK):
#this must be an old style template name- try to load the template
# this must be an old style template name-
# try to load the template
moa.template.installTemplate(
os.path.dirname(os.path.dirname(templateFile)),
_tempTemplate)
else:
noTemplate = True


if noTemplate:
self.name = 'nojob'
self.backend = 'nojob'
Expand All @@ -101,7 +98,6 @@ def __init__(self, templateFile):
original.load(self.templateFile)
self.original = original


l.debug("set template to %s, backend %s" % (self.name, self.backend))
if not self.name == 'nojob' and not self.modification_date:
self.modification_date = os.path.getmtime(self.templateFile)
Expand All @@ -111,20 +107,19 @@ def getRaw(self):
Return a Yaco representation of the yaml-template, without any
of this Template processing. This is really useful when
processing a template that needs to be written back to disk
>>> import moa.job
>>> job = moa.job.newTestJob(template='adhoc')
>>> job = moa.job.newTestJob(template='simple')
>>> raw = job.template.getRaw()
>>> assert(isinstance(raw, Yaco.Yaco))
>>> assert(raw.has_key('parameters'))
"""
y = Yaco.Yaco()
y.load(self.templateFile)
return y

def saveRaw(self, raw):
raw.save(self.templateFile)

def save(self):
raise Exception("direct saving of template files is disabled")

0 comments on commit aeae2e6

Please sign in to comment.