Skip to content

Commit

Permalink
forwarding refresh to the provider class
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Sep 28, 2012
1 parent 3d1004d commit 16e0c66
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions lib/python/moa/template/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@
import shutil

import Yaco
import moa.logger as l
import moa.logger
import moa.ui
from moa.template import provider
from moa.template.template import Template


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

PROVIDERS = provider.Providers()


Expand Down Expand Up @@ -65,7 +69,7 @@ def initTemplate(*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
{{wd}}/.moa/template.meta. If that doesn't work, revert to the
default template. If default is not specified - exit with an error
>>> import tempfile
Expand All @@ -83,19 +87,40 @@ def refresh(wd):
"""
meta = Yaco.Yaco()
metaFile = os.path.join(wd, '.moa', 'template.d', 'meta')
metaFile = os.path.join(wd, '.moa', 'template.meta')
l.debug("loading metafile from %s" % metaFile)

metaLoaded = False

try:
meta.load(metaFile)
metaLoaded = True
except (IOError):
pass

if not metaLoaded:
oldMetaFile = os.path.join(wd, '.moa', 'template.d', 'meta')
if os.path.exists(oldMetaFile):
shutil.move(oldMetaFile, metaFile)
try:
meta.load(metaFile)
metaLoaded = True
except (IOError):
pass

if not metaLoaded:
oldMetaFile = os.path.join(wd, '.moa', 'template.d', 'source')
if os.path.exists(oldMetaFile):
shutil.move(oldMetaFile, metaFile)
try:
meta.load(metaFile)
else:
l.critical("no template to refresh found in %s" % wd)
metaLoaded = True
except (IOError):
pass

if not metaLoaded:
moa.ui.exitError("no template to refresh recognized in %s" % wd)

if not meta.name and meta.source:
#old style
meta.name = meta.source
Expand All @@ -105,7 +130,7 @@ def refresh(wd):

l.debug("install template in %s" % wd)
l.debug("template name %s" % meta.name)
l.debug("from provider type %s" % meta['class'])
l.debug("from provider %s" % provider)

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

0 comments on commit 16e0c66

Please sign in to comment.