From 1ec79191d8c55902cc3ae58edd2a8ae62d29ae86 Mon Sep 17 00:00:00 2001 From: Louis Lacoste Date: Wed, 14 Sep 2022 16:32:16 +0200 Subject: [PATCH] Set the script to look for its config in its directory --- port-forwarder.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/port-forwarder.py b/port-forwarder.py index b70c108..c5e74fa 100644 --- a/port-forwarder.py +++ b/port-forwarder.py @@ -13,8 +13,11 @@ except ImportError: verbose = True action = "open" # open, close, status +SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) +config_path = SCRIPT_DIR + '/config.yaml' + # If no config exists we create one -if not os.path.exists("config.yaml"): +if not os.path.exists(config_path): print("No config file detected, populating one") dummy_config = """dummy-service: description: "Dummy service to change" @@ -26,7 +29,7 @@ config_data = "" if verbose: print("Reading the config") -with open("config.yaml", "r", encoding="utf8") as config_file: +with open(config_path, "r", encoding="utf8") as config_file: config_data = config_file.read() if not config_data: