summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Options/Actions.py
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2014-11-10 19:55:53 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2014-11-10 19:55:53 +0100
commit3f32d999c6e75af57058e389a07d1ab6a62eaebb (patch)
tree6055de1e6a541e2e5e4a721058f414a0e50258b6 /src/lib/Bcfg2/Options/Actions.py
parentda93fb540c28be3341ec0d37d1fbd90153fb750c (diff)
parent0e133c157755908d05c44c3a36b1dc0668e1d111 (diff)
downloadbcfg2-3f32d999c6e75af57058e389a07d1ab6a62eaebb.tar.gz
bcfg2-3f32d999c6e75af57058e389a07d1ab6a62eaebb.tar.bz2
bcfg2-3f32d999c6e75af57058e389a07d1ab6a62eaebb.zip
Merge branch 'options-unit-tests' of https://github.com/stpierre/bcfg2
* 'options-unit-tests' of https://github.com/stpierre/bcfg2: Options: Fixed non-path database name parsing Options: further command registry fixes Options: gather as much data from config file first Options: fix path canonicalization and file-like objects testsuite: unlink temporary files Options: ensure <repository> macros are always fixed up DBSettings: fix up <repository> in database name testsuite: better debug capturing for options tests call shutdown on subcommand registries fixed some places where plugin loading should fail silently testsuite: Added unit tests for new option parsing testsuite: capture stderr by default Test failure to parse config file when bcfg2.conf exists testsuite: skip nested exclusive option group test on py2.6 testsuite: Added unit tests for new option parsing
Diffstat (limited to 'src/lib/Bcfg2/Options/Actions.py')
-rw-r--r--src/lib/Bcfg2/Options/Actions.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Options/Actions.py b/src/lib/Bcfg2/Options/Actions.py
index 8b941f2bb..854e6039d 100644
--- a/src/lib/Bcfg2/Options/Actions.py
+++ b/src/lib/Bcfg2/Options/Actions.py
@@ -2,7 +2,8 @@
import sys
import argparse
-from Bcfg2.Options.Parser import get_parser
+from Bcfg2.Options.Parser import get_parser, OptionParserException
+from Bcfg2.Options.Options import _debug
__all__ = ["ConfigFileAction", "ComponentAction", "PluginsAction"]
@@ -101,7 +102,7 @@ class ComponentAction(FinalizableAction):
fail_silently = False
def __init__(self, *args, **kwargs):
- if self.mapping:
+ if self.mapping and not self.islist:
if 'choices' not in kwargs:
kwargs['choices'] = self.mapping.keys()
FinalizableAction.__init__(self, *args, **kwargs)
@@ -112,9 +113,12 @@ class ComponentAction(FinalizableAction):
try:
return getattr(__import__(module, fromlist=[name]), name)
except (AttributeError, ImportError):
+ msg = "Failed to load %s from %s: %s" % (name, module,
+ sys.exc_info()[1])
if not self.fail_silently:
- print("Failed to load %s from %s: %s" %
- (name, module, sys.exc_info()[1]))
+ print(msg)
+ else:
+ _debug(msg)
return None
def _load_component(self, name):
@@ -143,7 +147,7 @@ class ComponentAction(FinalizableAction):
if cls:
get_parser().add_component(cls)
elif not self.fail_silently:
- print("Could not load component %s" % name)
+ raise OptionParserException("Could not load component %s" % name)
return cls
def __call__(self, parser, namespace, values, option_string=None):
@@ -168,7 +172,10 @@ class ConfigFileAction(FinalizableAction):
``bcfg2-lint.conf``). """
def __call__(self, parser, namespace, values, option_string=None):
- parser.add_config_file(self.dest, values, reparse=False)
+ if values:
+ parser.add_config_file(self.dest, values, reparse=False)
+ else:
+ _debug("No config file passed for %s" % self)
FinalizableAction.__call__(self, parser, namespace, values,
option_string=option_string)
@@ -177,3 +184,4 @@ class PluginsAction(ComponentAction):
""" :class:`Bcfg2.Options.ComponentAction` subclass for loading
Bcfg2 server plugins. """
bases = ['Bcfg2.Server.Plugins']
+ fail_silently = True