library: move main code to explicit main() function

Without it, we unintentionally declared 3 global variables
(connections, cmd, run_env_ansible). This was not intended,
and results in possibly wrong behavior by accidentally using
the global variables.
This commit is contained in:
Thomas Haller 2018-06-11 08:45:49 +02:00
parent 63314aeb92
commit cf8522e5cc

View file

@ -2819,7 +2819,7 @@ class Cmd_initscripts(Cmd):
###############################################################################
if __name__ == '__main__':
def main():
connections = None
cmd = None
run_env_ansible = RunEnvironmentAnsible()
@ -2841,3 +2841,6 @@ if __name__ == '__main__':
warn_traceback = not isinstance(e, MyError))
run_env_ansible.exit_json(connections,
changed = (cmd is not None and cmd.is_changed_modified_system))
if __name__ == '__main__':
main()