From b52cc80b615eabb65ec7e169f8a3c011512c3696 Mon Sep 17 00:00:00 2001 From: Frisk Date: Thu, 18 Nov 2021 17:27:02 +0100 Subject: [PATCH] Fixes to previous commit --- src/misc.py | 14 +++++++------- src/rcgcdw.py | 4 ++-- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/misc.py b/src/misc.py index dece17a..348c9ad 100644 --- a/src/misc.py +++ b/src/misc.py @@ -48,15 +48,15 @@ profile_fields = {"profile-location": _("Location"), "profile-aboutme": _("About class DataFile: """Data class which instance of is shared by multiple modules to remain consistent and do not cause too many IO operations.""" def __init__(self): + self.data_filename = settings.get("datafile_path", "data.json") self.data = self.load_datafile() - misc_logger.debug("Current contents of data.json {}".format(self.data)) + misc_logger.debug("Current contents of {} {}".format(self.data_filename, self.data)) self.changed = False - @staticmethod - def generate_datafile(): + def generate_datafile(self): """Generate a data.json file from a template.""" try: - with open("data.json", 'w', encoding="utf-8") as data: + with open(self.data_filename, 'w', encoding="utf-8") as data: data.write(json.dumps(data_template, indent=4)) except PermissionError: misc_logger.critical("Could not create a data file (no permissions). No way to store last edit.") @@ -67,7 +67,7 @@ class DataFile: :rtype: dict """ try: - with open("data.json", encoding="utf-8") as data: + with open(self.data_filename, encoding="utf-8") as data: return json.loads(data.read()) except FileNotFoundError: self.generate_datafile() @@ -79,7 +79,7 @@ class DataFile: if self.changed is False: # don't cause unnecessary write operations return try: - with open(settings.get("datafile_path", "data.json"), "w", encoding="utf-8") as data_file: + with open(self.data_filename, "w", encoding="utf-8") as data_file: data_file.write(json.dumps(self.data, indent=4)) self.changed = False misc_logger.debug("Saving the database succeeded.") @@ -89,7 +89,7 @@ class DataFile: except OSError as e: if settings.get("error_tolerance", 1) > 1: if platform.system() == "Windows": - if "Invalid argument: 'data.json'" in str(e): + if "Invalid argument: '" + self.data_filename + "'" in str(e): misc_logger.error("Saving the data file failed due to Invalid argument exception, we've seen it " "before in issue #209, if you know the reason for it happening please reopen the " "issue with explanation, for now we are going to just ignore it.") # Reference #209 diff --git a/src/rcgcdw.py b/src/rcgcdw.py index 3dcc690..626adb4 100644 --- a/src/rcgcdw.py +++ b/src/rcgcdw.py @@ -24,7 +24,7 @@ import time, logging.config, requests, datetime, math, os.path, schedule, sys, r import src.misc import src.configloader from collections import defaultdict, Counter, OrderedDict - +from src.argparser import command_args from typing import Optional import src.api.client from src.api.context import Context @@ -41,7 +41,7 @@ settings = src.configloader.settings _ = rcgcdw.gettext ngettext = rcgcdw.ngettext -TESTING = True if "--test" in sys.argv else False # debug mode, pipeline testing +TESTING = command_args.test # debug mode, pipeline testing AUTO_SUPPRESSION_ENABLED = settings.get("auto_suppression", {"enabled": False}).get("enabled") if AUTO_SUPPRESSION_ENABLED: