From cf8522e5cc3b33b239c5dd34114bf70b23e150a5 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 11 Jun 2018 08:45:49 +0200 Subject: [PATCH] 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. --- library/network_connections.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/library/network_connections.py b/library/network_connections.py index 5fcdc84..c58014d 100644 --- a/library/network_connections.py +++ b/library/network_connections.py @@ -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()