mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-06 09:22:31 -05:00
* catch and handle FileNotFoundError when using --no-instance when config.json does not already exist
* move load_existing_config to data_manager.py
* use load_existing_config in create_temp_config
* Fix import in redbot-launcher
(cherry picked from commit cef55459c6)
Co-authored-by: Vexed <vex@vexcodes.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Vexed <vex@vexcodes.com>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
This commit is contained in:
@@ -46,6 +46,21 @@ if not config_dir:
|
||||
config_file = config_dir / "config.json"
|
||||
|
||||
|
||||
def load_existing_config():
|
||||
"""Get the contents of the config file, or an empty dictionary if it does not exist.
|
||||
|
||||
Returns
|
||||
-------
|
||||
dict
|
||||
The config data.
|
||||
"""
|
||||
if not config_file.exists():
|
||||
return {}
|
||||
|
||||
with config_file.open(encoding="utf-8") as fs:
|
||||
return json.load(fs)
|
||||
|
||||
|
||||
def create_temp_config():
|
||||
"""
|
||||
Creates a default instance for Red, so it can be ran
|
||||
@@ -61,8 +76,7 @@ def create_temp_config():
|
||||
default_dirs["STORAGE_TYPE"] = "JSON"
|
||||
default_dirs["STORAGE_DETAILS"] = {}
|
||||
|
||||
with config_file.open("r", encoding="utf-8") as fs:
|
||||
config = json.load(fs)
|
||||
config = load_existing_config()
|
||||
|
||||
config[name] = default_dirs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user