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

Commit 9818ec4

Browse files
committed
Re implememt Config class to be more generic. Fixes #524
- 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.
1 parent 1701d52 commit 9818ec4

File tree

6 files changed

+194
-217
lines changed

6 files changed

+194
-217
lines changed

atomicapp/cli/main.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ def cli_fetch(args):
6464
nm = NuleculeManager(app_spec=argdict['app_spec'],
6565
destination=destination,
6666
cli_answers=argdict['cli_answers'],
67-
answers_file=argdict['answers'])
67+
answers_file=argdict['answers'],
68+
answers_format=argdict.get('answers_format'))
6869
nm.fetch(**argdict)
6970
# Clean up the files if the user asked us to. Otherwise
7071
# notify the user where they can manage the application
@@ -81,7 +82,8 @@ def cli_run(args):
8182
nm = NuleculeManager(app_spec=argdict['app_spec'],
8283
destination=destination,
8384
cli_answers=argdict['cli_answers'],
84-
answers_file=argdict['answers'])
85+
answers_file=argdict['answers'],
86+
answers_format=argdict.get('answers_format'))
8587
nm.run(**argdict)
8688
# Clean up the files if the user asked us to. Otherwise
8789
# notify the user where they can manage the application
@@ -306,7 +308,7 @@ def create_parser(self):
306308
help="A file which will contain anwsers provided in interactive mode")
307309
run_subparser.add_argument(
308310
"--provider",
309-
dest="cli_provider",
311+
dest="provider",
310312
choices=PROVIDERS,
311313
help="The provider to use. Overrides provider value in answerfile.")
312314
run_subparser.add_argument(
@@ -511,7 +513,8 @@ def run(self):
511513
# and make a dictionary of it to pass along in args.
512514
setattr(args, 'cli_answers', {})
513515
for item in ['provider-api', 'provider-cafile', 'provider-auth',
514-
'provider-config', 'provider-tlsverify', 'namespace']:
516+
'provider-config', 'provider-tlsverify', 'namespace',
517+
'provider']:
515518
if hasattr(args, item) and getattr(args, item) is not None:
516519
args.cli_answers[item] = getattr(args, item)
517520

atomicapp/nulecule/base.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,8 @@ def load_from_path(cls, src, config=None, namespace=GLOBAL_CONF,
176176
raise NuleculeException("Failure parsing %s file. Validation error on line %s, column %s:\n%s"
177177
% (nulecule_path, line, column, output))
178178

179-
nulecule = Nulecule(config=config,
180-
basepath=src, namespace=namespace,
181-
**nulecule_data)
179+
nulecule = Nulecule(config=config, basepath=src,
180+
namespace=namespace, **nulecule_data)
182181
nulecule.load_components(nodeps, dryrun)
183182
return nulecule
184183

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

253252
def load_components(self, nodeps=False, dryrun=False):
@@ -294,6 +293,18 @@ def render(self, provider_key=None, dryrun=False):
294293
component.render(provider_key=provider_key, dryrun=dryrun)
295294

296295
def _get_component_namespace(self, component_name):
296+
"""
297+
Get a unique namespace for a Nulecule graph item, by concatinating
298+
the namespace of the current Nulecule (which could be the root Nulecule
299+
app or a child or external Nulecule app) and name of the Nulecule
300+
graph item.
301+
302+
Args:
303+
component_name (str): Name of the Nulecule graph item
304+
305+
Returns:
306+
A string
307+
"""
297308
current_namespace = '' if self.namespace == GLOBAL_CONF else self.namespace
298309
return (
299310
'%s%s%s' % (current_namespace, NAMESPACE_SEPARATOR, component_name)
@@ -366,7 +377,7 @@ def load_config(self, config=None, ask=False, skip_asking=False):
366377
super(NuleculeComponent, self).load_config(
367378
config, ask=ask, skip_asking=skip_asking)
368379
if isinstance(self._app, Nulecule):
369-
self._app.load_config(config=self.config.clone(self.namespace),
380+
self._app.load_config(config=self.config,
370381
ask=ask, skip_asking=skip_asking)
371382

372383
def load_external_application(self, dryrun=False, update=False):
@@ -443,7 +454,7 @@ def render(self, provider_key=None, dryrun=False):
443454
raise NuleculeException(
444455
"Data for provider \"%s\" are not part of this app"
445456
% provider_key)
446-
context = self.get_context()
457+
context = self.config.context(self.namespace)
447458
for provider in self.artifacts:
448459
if provider_key and provider != provider_key:
449460
continue

0 commit comments

Comments
 (0)