Skip to content

Commit

Permalink
Fix namespace conflicts in answers.conf. Fixes projectatomic#478
Browse files Browse the repository at this point in the history
  • Loading branch information
rtnpro committed Dec 31, 2015
1 parent e478688 commit 6d0b411
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 8 additions & 2 deletions atomicapp/nulecule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ def load_components(self, nodeps=False, dryrun=False):
node_name = node[NAME_KEY]
source = Utils.getSourceImage(node)
component = NuleculeComponent(
node_name, self.basepath, source,
node.get(PARAMS_KEY), node.get(ARTIFACTS_KEY))
self._get_component_namespace(node_name), self.basepath,
source, node.get(PARAMS_KEY), node.get(ARTIFACTS_KEY))
component.load(nodeps, dryrun)
components.append(component)
self.components = components
Expand All @@ -222,6 +222,12 @@ def render(self, provider_key=None, dryrun=False):
for component in self.components:
component.render(provider_key=provider_key, dryrun=dryrun)

def _get_component_namespace(self, component_name):
current_namespace = '' if self.namespace == GLOBAL_CONF else self.namespace
return (
'%s:%s' % (current_namespace, component_name)
if current_namespace else component_name)


class NuleculeComponent(NuleculeBase):
"""
Expand Down
6 changes: 6 additions & 0 deletions atomicapp/nulecule/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ def load_config(self, config, ask=False, skip_asking=False):
Returns:
None
"""
parent_namespace = self._get_parent_namespace()
for param in self.params:
value = config.get(self.namespace, {}).get(param[NAME_KEY]) or \
config.get(parent_namespace, {}).get(param[NAME_KEY]) or \
config.get(GLOBAL_CONF, {}).get(param[NAME_KEY])
if value is None and (ask or (
not skip_asking and param.get(DEFAULTNAME_KEY) is None)):
Expand Down Expand Up @@ -109,3 +111,7 @@ def install(self):

def uninstall(self):
raise NotImplementedError

def _get_parent_namespace(self):
tokens = self.namespace.split(':')
return ':'.join(tokens[:-1]) if len(tokens) > 1 else GLOBAL_CONF

0 comments on commit 6d0b411

Please sign in to comment.