mirror of
https://github.com/samba-team/samba.git
synced 2025-02-03 13:47:25 +03:00
utils: Move argument processing into function and call from main()
Removes the need for the global variables currently associated with this processing. Also removes unnecessarily double-handling the defaults, which are assigned to the global variables and set via add_argument(). Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: David Disseldorp <ddiss@samba.org> Reviewed-by: Jose A. Rivera <jarrpa@samba.org>
This commit is contained in:
parent
e66637a079
commit
af5aecced1
@ -80,13 +80,32 @@ log_levels = {0: logging.ERROR,
|
||||
2: logging.DEBUG,
|
||||
}
|
||||
|
||||
config_file = defaults['config']
|
||||
verbose = defaults['verbose']
|
||||
|
||||
# Helper Functions ------------------------------------------------------------
|
||||
#
|
||||
|
||||
|
||||
def process_args():
|
||||
'''Process command-line arguments and return them.
|
||||
'''
|
||||
parser = argparse.ArgumentParser(
|
||||
description=__doc__,
|
||||
epilog='',
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('-v', '--verbose',
|
||||
action='count',
|
||||
help=helpmsg['verbose'],
|
||||
default=defaults['verbose'],
|
||||
)
|
||||
parser.add_argument('-c', '--config',
|
||||
action='store',
|
||||
help=helpmsg['config'],
|
||||
default=defaults['config'],
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def sigterm_handler(signum, frame):
|
||||
"""Handler for SIGTERM signals.
|
||||
"""
|
||||
@ -113,9 +132,9 @@ def int_or_not(s):
|
||||
|
||||
|
||||
def main():
|
||||
global config_file
|
||||
global verbose
|
||||
args = process_args()
|
||||
|
||||
verbose = args.verbose if args.verbose <= 2 else 2
|
||||
logging.basicConfig(level=log_levels[verbose])
|
||||
|
||||
# etcd config defaults
|
||||
@ -143,8 +162,8 @@ def main():
|
||||
'expected_cluster_id',
|
||||
'per_host_pool_size',
|
||||
)
|
||||
if os.path.isfile(config_file):
|
||||
f = open(config_file, 'r')
|
||||
if os.path.isfile(args.config):
|
||||
f = open(args.config, 'r')
|
||||
for line in f:
|
||||
(key, value) = line.split("=", 1)
|
||||
etcd_config[key.strip()] = int_or_not(value.strip())
|
||||
@ -195,23 +214,4 @@ def main():
|
||||
if __name__ == "__main__":
|
||||
signal.signal(signal.SIGTERM, sigterm_handler)
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description=__doc__,
|
||||
epilog='',
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter)
|
||||
parser.add_argument('-v', '--verbose',
|
||||
action='count',
|
||||
help=helpmsg['verbose'],
|
||||
default=defaults['verbose'],
|
||||
)
|
||||
parser.add_argument('-c', '--config',
|
||||
action='store',
|
||||
help=helpmsg['config'],
|
||||
default=defaults['config'],
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
config_file = args.config
|
||||
verbose = args.verbose if args.verbose <= 2 else 2
|
||||
|
||||
main()
|
||||
|
Loading…
x
Reference in New Issue
Block a user