Skip to content

Commit

Permalink
safer template provider import
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Fiers committed Oct 23, 2012
1 parent 5897222 commit 4a02a78
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/python/moa/template/provider/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,21 @@ def __init__(self):
_order = []
for pName in sysConf.template.providers.keys():
pInfo = sysConf.template.providers[pName]

is_enabled = pInfo.get('enabled', False)
if not is_enabled is True:
continue

priority = pInfo.get('priority', 1)
assert(isinstance(priority, int))

#import the correct module
mod = 'moa.template.provider.%s' % pInfo['class']
pMod = __import__(mod, globals(), locals(), [mod], -1)
try:
pMod = __import__(mod, globals(), locals(), [mod], -1)
except ImportError:
moa.ui.warn("cannot import template provider %s" % pName)
continue

#instantiate the class (mod.Mod())
self.providers[pName] = \
Expand Down

0 comments on commit 4a02a78

Please sign in to comment.