Optimize the code

Keeping function code together can make the structure clear

Change-Id: Ia16b43b902543bc57869579acba2f6b3d5f2ca54
This commit is contained in:
zhuzeyu 2017-03-16 09:34:17 +08:00
parent cf6883b82b
commit 730cd93771
1 changed files with 20 additions and 21 deletions

View File

@ -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()
try:
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 args.check:
execute_config_check(config)
else:
execute_config_strategy(config)
except ExitingException as e:
LOG.error("%s: %s", e.__class__.__name__, e)
return e.exit_code
except Exception:
LOG.exception('Unexpected error:')
return 2
return 0
if __name__ == "__main__":
_exit_code = 0
try:
main()
except ExitingException as e:
LOG.error("%s: %s", e.__class__.__name__, e)
_exit_code = e.exit_code
except Exception:
LOG.exception('Unexpected error:')
_exit_code = 2
sys.exit(_exit_code)
sys.exit(main())