from overrides import overrides
-
# This module is commonly used by others in here and should avoid
# taking any unnecessary dependencies back on them.
class ActionNoYes(argparse.Action):
- def __init__(
- self,
- option_strings,
- dest,
- default=None,
- required=False,
- help=None
- ):
+ def __init__(self, option_strings, dest, default=None, required=False, help=None):
if default is None:
msg = 'You must provide a default with Yes/No action'
logger.critical(msg)
const=None,
default=default,
required=required,
- help=help
+ help=help,
)
@overrides
def __call__(self, parser, namespace, values, option_strings=None):
- if (
- option_strings.startswith('--no-') or
- option_strings.startswith('--no_')
- ):
+ if option_strings.startswith('--no-') or option_strings.startswith('--no_'):
setattr(namespace, self.dest, False)
else:
setattr(namespace, self.dest, True)
if isinstance(v, bool):
return v
from string_utils import to_bool
+
try:
return to_bool(v)
except Exception:
"""
from string_utils import extract_ip_v4
+
s = extract_ip_v4(ip.strip())
if s is not None:
return s
"""
from string_utils import extract_mac_address
+
s = extract_mac_address(mac)
if s is not None:
return s
-ANYTHING-
"""
from string_utils import to_date
+
date = to_date(txt)
if date is not None:
return date
-ANYTHING-
"""
from string_utils import to_datetime
+
dt = to_datetime(txt)
if dt is not None:
return dt
"""
from datetime_utils import parse_duration
+
try:
secs = parse_duration(txt)
except Exception as e:
if __name__ == '__main__':
import doctest
+
doctest.ELLIPSIS_MARKER = '-ANYTHING-'
doctest.testmod()