Skip to content
This repository has been archived by the owner on Jan 19, 2018. It is now read-only.

Commit

Permalink
Re implememt Config class to be more generic. Fixes #524
Browse files Browse the repository at this point in the history
- Create single source of truth for config data in NuleculeManager.
  Get rid of answers and cli_answers instance variables, and use only
  self.config to look up config data.
- Allow ignoring sources when getting data from config.
- Allow specifying file format when loading answers.
  • Loading branch information
rtnpro committed Aug 10, 2016
1 parent 1701d52 commit baa68ce
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 216 deletions.
11 changes: 7 additions & 4 deletions atomicapp/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def cli_fetch(args):
nm = NuleculeManager(app_spec=argdict['app_spec'],
destination=destination,
cli_answers=argdict['cli_answers'],
answers_file=argdict['answers'])
answers_file=argdict['answers'],
answers_format=argdict.get('answers_format'))
nm.fetch(**argdict)
# Clean up the files if the user asked us to. Otherwise
# notify the user where they can manage the application
Expand All @@ -81,7 +82,8 @@ def cli_run(args):
nm = NuleculeManager(app_spec=argdict['app_spec'],
destination=destination,
cli_answers=argdict['cli_answers'],
answers_file=argdict['answers'])
answers_file=argdict['answers'],
answers_format=argdict.get('answers_format'))
nm.run(**argdict)
# Clean up the files if the user asked us to. Otherwise
# notify the user where they can manage the application
Expand Down Expand Up @@ -306,7 +308,7 @@ def create_parser(self):
help="A file which will contain anwsers provided in interactive mode")
run_subparser.add_argument(
"--provider",
dest="cli_provider",
dest="provider",
choices=PROVIDERS,
help="The provider to use. Overrides provider value in answerfile.")
run_subparser.add_argument(
Expand Down Expand Up @@ -511,7 +513,8 @@ def run(self):
# and make a dictionary of it to pass along in args.
setattr(args, 'cli_answers', {})
for item in ['provider-api', 'provider-cafile', 'provider-auth',
'provider-config', 'provider-tlsverify', 'namespace']:
'provider-config', 'provider-tlsverify', 'namespace',
'provider']:
if hasattr(args, item) and getattr(args, item) is not None:
args.cli_answers[item] = getattr(args, item)

Expand Down
23 changes: 17 additions & 6 deletions atomicapp/nulecule/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ def load_from_path(cls, src, config=None, namespace=GLOBAL_CONF,
raise NuleculeException("Failure parsing %s file. Validation error on line %s, column %s:\n%s"
% (nulecule_path, line, column, output))

nulecule = Nulecule(config=config,
basepath=src, namespace=namespace,
**nulecule_data)
nulecule = Nulecule(config=config, basepath=src,
namespace=namespace, **nulecule_data)
nulecule.load_components(nodeps, dryrun)
return nulecule

Expand Down Expand Up @@ -247,7 +246,7 @@ def load_config(self, config=None, ask=False, skip_asking=False):
# FIXME: Find a better way to expose config data to components.
# A component should not get access to all the variables,
# but only to variables it needs.
component.load_config(config=config.clone(component.namespace),
component.load_config(config=config,
ask=ask, skip_asking=skip_asking)

def load_components(self, nodeps=False, dryrun=False):
Expand Down Expand Up @@ -294,6 +293,18 @@ def render(self, provider_key=None, dryrun=False):
component.render(provider_key=provider_key, dryrun=dryrun)

def _get_component_namespace(self, component_name):
"""
Get a unique namespace for a Nulecule graph item, by concatinating
the namespace of the current Nulecule (which could be the root Nulecule
app or a child or external Nulecule app) and name of the Nulecule
graph item.
Args:
component_name (str): Name of the Nulecule graph item
Returns:
A string
"""
current_namespace = '' if self.namespace == GLOBAL_CONF else self.namespace
return (
'%s%s%s' % (current_namespace, NAMESPACE_SEPARATOR, component_name)
Expand Down Expand Up @@ -366,7 +377,7 @@ def load_config(self, config=None, ask=False, skip_asking=False):
super(NuleculeComponent, self).load_config(
config, ask=ask, skip_asking=skip_asking)
if isinstance(self._app, Nulecule):
self._app.load_config(config=self.config.clone(self.namespace),
self._app.load_config(config=self.config,
ask=ask, skip_asking=skip_asking)

def load_external_application(self, dryrun=False, update=False):
Expand Down Expand Up @@ -443,7 +454,7 @@ def render(self, provider_key=None, dryrun=False):
raise NuleculeException(
"Data for provider \"%s\" are not part of this app"
% provider_key)
context = self.get_context()
context = self.config.context(self.namespace)
for provider in self.artifacts:
if provider_key and provider != provider_key:
continue
Expand Down
Loading

0 comments on commit baa68ce

Please sign in to comment.