summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Options
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2014-07-15 10:54:55 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2014-07-15 10:54:55 -0400
commit16bb58a7110daeb479fdf41e5c67f45dc3502fc5 (patch)
treee2d4da726b6ed0a37187d57d5d9367bc30a4d33b /src/lib/Bcfg2/Options
parent1f3f4c79fb4bb0684a000c169774c7b62816ff5a (diff)
parentc76fb188215208fcfc5af9027f16447855a6f064 (diff)
downloadbcfg2-16bb58a7110daeb479fdf41e5c67f45dc3502fc5.tar.gz
bcfg2-16bb58a7110daeb479fdf41e5c67f45dc3502fc5.tar.bz2
bcfg2-16bb58a7110daeb479fdf41e5c67f45dc3502fc5.zip
Merge pull request #180 from fennm/default-fam_blocking-to-true
Default fam blocking to true
Diffstat (limited to 'src/lib/Bcfg2/Options')
-rw-r--r--src/lib/Bcfg2/Options/Options.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/src/lib/Bcfg2/Options/Options.py b/src/lib/Bcfg2/Options/Options.py
index 11388fb4d..3874f810d 100644
--- a/src/lib/Bcfg2/Options/Options.py
+++ b/src/lib/Bcfg2/Options/Options.py
@@ -306,6 +306,26 @@ class PathOption(Option):
Option.__init__(self, *args, **kwargs)
+class _BooleanOptionAction(argparse.Action):
+ """ BooleanOptionAction sets a boolean value in the following ways:
+ - if None is passed, store the default
+ - if the option_string is not None, then the option was passed on the
+ command line, thus store the opposite of the default (this is the
+ argparse store_true and store_false behavior)
+ - if a boolean value is passed, use that
+
+ Defined here instead of :mod:`Bcfg2.Options.Actions` because otherwise
+ there is a circular import Options -> Actions -> Parser -> Options """
+
+ def __call__(self, parser, namespace, values, option_string=None):
+ if values is None:
+ setattr(namespace, self.dest, self.default)
+ elif option_string is not None:
+ setattr(namespace, self.dest, not self.default)
+ else:
+ setattr(namespace, self.dest, bool(values))
+
+
class BooleanOption(Option):
""" Shortcut for boolean options. The default is False, but this
can easily be overridden:
@@ -317,11 +337,10 @@ class BooleanOption(Option):
"--dwim", default=True, help="Do What I Mean")]
"""
def __init__(self, *args, **kwargs):
- if 'default' in kwargs and kwargs['default']:
- kwargs.setdefault('action', 'store_false')
- else:
- kwargs.setdefault('action', 'store_true')
- kwargs.setdefault('default', False)
+ kwargs.setdefault('action', _BooleanOptionAction)
+ kwargs.setdefault('nargs', 0)
+ kwargs.setdefault('default', False)
+
Option.__init__(self, *args, **kwargs)