From 087eb0d5946191d7c79a6268ac3b55810c477b25 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 2 Sep 2019 16:05:37 +0200 Subject: [PATCH] Don't crash if config.ini does not exist --- configloader.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/configloader.py b/configloader.py index 4cdd93b..ad96b43 100644 --- a/configloader.py +++ b/configloader.py @@ -2,13 +2,14 @@ import sys import os import configparser -# Check if a configuration file exists, create one if it doesn't and get the template version number. -with open("config/template_config.ini") as template_file: - # Check if the config file exists - if not os.path.isfile("config/config.ini"): +# Check if the config file exists, and create one if it doesn't +if not os.path.isfile("config/config.ini"): + # Open the template file and create the config file + with open("config/template_config.ini") as template_file, open("config/config.ini", "w") as config_file: # Copy the template file to the config file - with open("config/config.ini", "w") as config_file: - config_file.write(template_file.read()) + config_file.write(template_file.read()) + +with open("config/template_config.ini") as template_file: # Find the template version number config = configparser.ConfigParser() config.read_file(template_file)