-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path__init__.py
32 lines (24 loc) · 856 Bytes
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import argparse
class Configurable(object):
@staticmethod
def modify_commandline_options(parser):
"""Add new options, and rewrite default values for existing options.
Parameters:
parser -- original option parser
Returns:
the modified parser.
"""
return parser
def get_option_setter(obj):
if issubclass(obj, Configurable):
return obj.modify_commandline_options
print('Class', obj, 'is not a subclass of Configurable, hence unable to modify commandline arguments.')
def str2bool(v):
if isinstance(v, bool):
return v
if v.lower() in ('yes', 'true', 't', 'y', '1'):
return True
elif v.lower() in ('no', 'false', 'f', 'n', '0'):
return False
else:
raise argparse.ArgumentTypeError('Boolean value expected.')