Skip to content

Commit

Permalink
fixed unittests
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 13, 2012
1 parent 16533c7 commit dacccb7
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions lib/python/moa/template/__init__.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
------------
Expand Down Expand Up @@ -32,11 +32,13 @@

def getMoaFile(name):
return PROVIDERS.getTemplate(name)



def templateList():
x = PROVIDERS.templateList()
return x


def installTemplate(wd, tName, provider=None):
"""
Initialize the template - this means - try to figure out where the
Expand All @@ -48,41 +50,42 @@ def installTemplate(wd, tName, provider=None):
>>> import tempfile
>>> wd = tempfile.mkdtemp()
>>> installTemplate(wd, 'adhoc')
>>> installTemplate(wd, 'simple')
>>> templateFile = os.path.join(wd, '.moa', 'template')
>>> adhocFile = os.path.join(wd, '.moa', 'template.d', 'adhoc.mk')
>>> adhocFile = os.path.join(wd, '.moa', 'template.d', 'simple.jinja2')
>>> assert(os.path.exists(templateFile))
>>> assert(os.path.exists(adhocFile))
"""
PROVIDERS.installTemplate(wd, tName, provider)


def initTemplate(*args, **kwargs):
"""
"""
l.warning("Deprecated call")
installTemplate(*args, **kwargs)


def refresh(wd):
"""
Refresh the template - try to find out what the template is from
{{wd}}/.moa/template.d/meta. If that doesn't work, revert to the
Refresh the template - try to find out what the template is from
{{wd}}/.moa/template.d/meta. If that doesn't work, revert to the
default template. If default is not specified - exit with an error
>>> import tempfile
>>> wd = tempfile.mkdtemp()
>>> installTemplate(wd, 'adhoc')
>>> installTemplate(wd, 'simple')
>>> templateFile = os.path.join(wd, '.moa', 'template')
>>> adhocFile = os.path.join(wd, '.moa', 'template.d', 'adhoc.mk')
>>> os.unlink(adhocFile)
>>> adhocFile = os.path.join(wd, '.moa', 'template.d', 'simple.jinja2')
>>> os.unlink(adhocFile)
>>> os.unlink(templateFile)
>>> assert(not os.path.exists(templateFile))
>>> assert(not os.path.exists(adhocFile))
>>> refresh(wd)
>>> assert(os.path.exists(templateFile))
>>> assert(os.path.exists(adhocFile))
"""
meta = Yaco.Yaco()
metaFile = os.path.join(wd, '.moa', 'template.d', 'meta')
Expand All @@ -99,17 +102,17 @@ def refresh(wd):
pass

if not meta.name and meta.source:
#old style
#old style
meta.name = meta.source
if not meta.name:

if not meta.name:
moa.ui.exitError("Cannot refresh this job")

l.debug("install template in %s" % wd)
l.debug("template name %s" % meta.name)
l.debug("from provider %s" % provider)

installTemplate(wd,
tName = meta.name,
provider=meta.get('provider', None))

0 comments on commit dacccb7

Please sign in to comment.