Fixes to previous commit

This commit is contained in:
Frisk 2021-11-18 17:27:02 +01:00
parent b63aadb74d
commit b52cc80b61
No known key found for this signature in database
GPG key ID: 213F7C15068AF8AC
2 changed files with 9 additions and 9 deletions

View file

@ -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

View file

@ -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: