From 730cd93771e4d1fcf41351e80f8cc8540c563bc7 Mon Sep 17 00:00:00 2001 From: zhuzeyu Date: Thu, 16 Mar 2017 09:34:17 +0800 Subject: Optimize the code Keeping function code together can make the structure clear Change-Id: Ia16b43b902543bc57869579acba2f6b3d5f2ca54 --- docker/base/set_configs.py | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'docker/base') diff --git a/docker/base/set_configs.py b/docker/base/set_configs.py index a2d875a47..9c3d1f1e4 100644 --- a/docker/base/set_configs.py +++ b/docker/base/set_configs.py @@ -392,28 +392,27 @@ def execute_config_check(config): def main(): - parser = argparse.ArgumentParser() - parser.add_argument('--check', - action='store_true', - required=False, - help='Check whether the configs changed') - args = parser.parse_args() - config = load_config() - - if args.check: - execute_config_check(config) - else: - execute_config_strategy(config) - - -if __name__ == "__main__": - _exit_code = 0 try: - main() + parser = argparse.ArgumentParser() + parser.add_argument('--check', + action='store_true', + required=False, + help='Check whether the configs changed') + args = parser.parse_args() + config = load_config() + + if args.check: + execute_config_check(config) + else: + execute_config_strategy(config) except ExitingException as e: LOG.error("%s: %s", e.__class__.__name__, e) - _exit_code = e.exit_code + return e.exit_code except Exception: LOG.exception('Unexpected error:') - _exit_code = 2 - sys.exit(_exit_code) + return 2 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) -- cgit v1.2.3