mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 18:57:59 -05:00
Kill JsonIO and fix JSON driver caching issues (#2796)
* Kill JsonIO and fix JSON driver caching issues Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Ensure lock covers critical region in set() Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Make tests pass Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Use pickle over deepcopy in Config Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Fix temp instance creation Signed-off-by: Toby Harradine <tobyharradine@gmail.com> * Serialise value before doing anything in set() Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
committed by
Michael H
parent
f3bbfdc64d
commit
bff7e214ab
@@ -1,16 +1,17 @@
|
||||
import inspect
|
||||
import json
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
from copy import deepcopy
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict
|
||||
|
||||
import appdirs
|
||||
from discord.utils import deprecated
|
||||
|
||||
from . import commands
|
||||
from .json_io import JsonIO
|
||||
|
||||
__all__ = [
|
||||
"create_temp_config",
|
||||
@@ -25,12 +26,15 @@ __all__ = [
|
||||
|
||||
log = logging.getLogger("red.data_manager")
|
||||
|
||||
jsonio = None
|
||||
basic_config = None
|
||||
|
||||
instance_name = None
|
||||
|
||||
basic_config_default = {"DATA_PATH": None, "COG_PATH_APPEND": "cogs", "CORE_PATH_APPEND": "core"}
|
||||
basic_config_default: Dict[str, Any] = {
|
||||
"DATA_PATH": None,
|
||||
"COG_PATH_APPEND": "cogs",
|
||||
"CORE_PATH_APPEND": "core",
|
||||
}
|
||||
|
||||
config_dir = None
|
||||
appdir = appdirs.AppDirs("Red-DiscordBot")
|
||||
@@ -57,9 +61,13 @@ def create_temp_config():
|
||||
default_dirs["STORAGE_TYPE"] = "JSON"
|
||||
default_dirs["STORAGE_DETAILS"] = {}
|
||||
|
||||
config = JsonIO(config_file)._load_json()
|
||||
with config_file.open("r", encoding="utf-8") as fs:
|
||||
config = json.load(fs)
|
||||
|
||||
config[name] = default_dirs
|
||||
JsonIO(config_file)._save_json(config)
|
||||
|
||||
with config_file.open("w", encoding="utf-8") as fs:
|
||||
json.dump(config, fs, indent=4)
|
||||
|
||||
|
||||
def load_basic_configuration(instance_name_: str):
|
||||
@@ -76,23 +84,21 @@ def load_basic_configuration(instance_name_: str):
|
||||
The instance name given by CLI argument and created during
|
||||
redbot setup.
|
||||
"""
|
||||
global jsonio
|
||||
global basic_config
|
||||
global instance_name
|
||||
|
||||
jsonio = JsonIO(config_file)
|
||||
|
||||
instance_name = instance_name_
|
||||
|
||||
try:
|
||||
config = jsonio._load_json()
|
||||
basic_config = config[instance_name]
|
||||
with config_file.open(encoding="utf-8") as fs:
|
||||
config = json.load(fs)
|
||||
except (FileNotFoundError, KeyError):
|
||||
print(
|
||||
"You need to configure the bot instance using `redbot-setup`"
|
||||
" prior to running the bot."
|
||||
)
|
||||
sys.exit(1)
|
||||
else:
|
||||
basic_config = config[instance_name]
|
||||
|
||||
|
||||
def _base_data_path() -> Path:
|
||||
|
||||
Reference in New Issue
Block a user