mirror of
https://github.com/Steffo99/greed.git
synced 2024-11-22 05:54:18 +00:00
Use logging in configloader (even if it doesn't show up)
This commit is contained in:
parent
68eafef656
commit
71a3683cc1
2 changed files with 19 additions and 11 deletions
|
@ -1,9 +1,16 @@
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import configparser
|
import configparser
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
# Logs won't show up for this file as it is imported before logging is configured
|
||||||
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
# Check if the config file exists, and create one if it doesn't
|
# Check if the config file exists, and create one if it doesn't
|
||||||
if not os.path.isfile("config/config.ini"):
|
if not os.path.isfile("config/config.ini"):
|
||||||
|
log.debug("Creating config.ini from template_config.ini")
|
||||||
# Open the template file and create the config file
|
# 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:
|
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
|
# Copy the template file to the config file
|
||||||
|
@ -14,27 +21,34 @@ with open("config/template_config.ini") as template_file:
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read_file(template_file)
|
config.read_file(template_file)
|
||||||
template_version = int(config["Config"]["version"])
|
template_version = int(config["Config"]["version"])
|
||||||
|
log.debug(f"Template is version {template_version}")
|
||||||
|
|
||||||
# Overwrite the template config with the values in the config
|
# Overwrite the template config with the values in the config
|
||||||
with open("config/config.ini") as config_file:
|
with open("config/config.ini") as config_file:
|
||||||
config.read_file(config_file)
|
config.read_file(config_file)
|
||||||
|
config_version = int(config["Config"]["version"])
|
||||||
|
log.debug(f"Config is version {template_version}")
|
||||||
|
|
||||||
# Check if the file has been edited
|
# Check if the file has been edited
|
||||||
if config["Config"]["is_template"] == "yes":
|
if config["Config"]["is_template"] == "yes":
|
||||||
print("A config file has been created in config/config.ini.\n"
|
log.debug("Config is a template, aborting...")
|
||||||
"Edit it with your configuration, set the is_template flag to false and restart this script.")
|
log.fatal("A config file has been created in config/config.ini.\n"
|
||||||
|
"Edit it with your configuration, set the is_template flag to 'no' and restart this script.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check if the version has changed from the template
|
# Check if the version has changed from the template
|
||||||
if template_version > int(config["Config"]["version"]):
|
if template_version > config_version:
|
||||||
|
log.debug("Config is older than Template, trying to merge...")
|
||||||
# Reset the is_template flag
|
# Reset the is_template flag
|
||||||
config["Config"]["is_template"] = "yes"
|
config["Config"]["is_template"] = "yes"
|
||||||
# Update the config version
|
# Update the config version
|
||||||
config["Config"]["version"] = str(template_version)
|
config["Config"]["version"] = str(template_version)
|
||||||
# Save the file
|
# Save the file
|
||||||
with open("config/config.ini", "w") as config_file:
|
with open("config/config.ini", "w") as config_file:
|
||||||
|
log.debug("Writing merged config file...")
|
||||||
config.write(config_file)
|
config.write(config_file)
|
||||||
# Notify the user and quit
|
# Notify the user and quit
|
||||||
print("The config file in config/config.ini has been updated.\n"
|
log.debug("Config is now a template, aborting...")
|
||||||
"Edit it with the new required data, set the is_template flag to true and restart this script.")
|
log.fatal("The config file in config/config.ini has been updated.\n"
|
||||||
|
"Edit it with the new required data, set the is_template flag to true and restart this script.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
|
@ -16,11 +16,6 @@ import requests
|
||||||
import importlib
|
import importlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
try:
|
|
||||||
import coloredlogs
|
|
||||||
except ImportError:
|
|
||||||
coloredlogs = None
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
language = configloader.config["Config"]["language"]
|
language = configloader.config["Config"]["language"]
|
||||||
|
@ -29,7 +24,6 @@ strings = importlib.import_module("strings." + language)
|
||||||
|
|
||||||
class StopSignal:
|
class StopSignal:
|
||||||
"""A data class that should be sent to the worker when the conversation has to be stopped abnormally."""
|
"""A data class that should be sent to the worker when the conversation has to be stopped abnormally."""
|
||||||
|
|
||||||
def __init__(self, reason: str = ""):
|
def __init__(self, reason: str = ""):
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue