mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -05:00
[V3 Everything] Package bot and write setup scripts (#964)
Ya'll are gonna hate me. * Initial modifications * Add initial setup.py * working setup py help * Modify setup file to package stuff * Move a bunch of shit and fix imports * Fix or skip tests * Must add init files for find_packages to work * Move main to scripts folder and rename * Add shebangs * Copy over translation files * WORKING PIP INSTALL * add dependency information * Hardcoded version for now, will need to figure out a better way to do this * OKAY ITS FINALLY FUCKING WORKING * Add this guy * Fix stuff * Change readme to rst * Remove double sentry opt in * Oopsie * Fix this thing * Aaaand fix test * Aaaand fix test * Fix core cog importing and default cog install path * Adjust readme * change instance name from optional to required * Ayyy let's do more dependency injection
This commit is contained in:
74
redbot/core/data_manager.py
Normal file
74
redbot/core/data_manager.py
Normal file
@@ -0,0 +1,74 @@
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import appdirs
|
||||
|
||||
from .json_io import JsonIO
|
||||
|
||||
jsonio = None
|
||||
basic_config = None
|
||||
|
||||
basic_config_default = {
|
||||
"DATA_PATH": None,
|
||||
"COG_PATH_APPEND": "cogs",
|
||||
"CORE_PATH_APPEND": "core"
|
||||
}
|
||||
|
||||
config_dir = Path(appdirs.AppDirs("Red-DiscordBot").user_config_dir)
|
||||
config_file = config_dir / 'config.json'
|
||||
|
||||
|
||||
def load_basic_configuration(instance_name: str):
|
||||
global jsonio
|
||||
global basic_config
|
||||
|
||||
jsonio = JsonIO(config_file)
|
||||
|
||||
try:
|
||||
config = jsonio._load_json()
|
||||
basic_config = config[instance_name]
|
||||
except (FileNotFoundError, KeyError):
|
||||
print("You need to configure the bot instance using `redbot-setup`"
|
||||
" prior to running the bot.")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def _base_data_path() -> Path:
|
||||
if basic_config is None:
|
||||
raise RuntimeError("You must load the basic config before you"
|
||||
" can get the base data path.")
|
||||
path = basic_config['DATA_PATH']
|
||||
return Path(path).resolve()
|
||||
|
||||
|
||||
def cog_data_path(cog_instance=None) -> Path:
|
||||
"""
|
||||
Gets the base cog data path. If you want to get the folder with
|
||||
which to store your own cog's data please pass in an instance
|
||||
of your cog class.
|
||||
:param cog_instance:
|
||||
:return:
|
||||
"""
|
||||
try:
|
||||
base_data_path = Path(_base_data_path())
|
||||
except RuntimeError as e:
|
||||
raise RuntimeError("You must load the basic config before you"
|
||||
" can get the cog data path.") from e
|
||||
cog_path = base_data_path / basic_config['COG_PATH_APPEND']
|
||||
if cog_instance:
|
||||
cog_path = cog_path / cog_instance.__class__.__name__
|
||||
cog_path.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
return cog_path.resolve()
|
||||
|
||||
|
||||
def core_data_path() -> Path:
|
||||
try:
|
||||
base_data_path = Path(_base_data_path())
|
||||
except RuntimeError as e:
|
||||
raise RuntimeError("You must load the basic config before you"
|
||||
" can get the core data path.") from e
|
||||
core_path = base_data_path / basic_config['CORE_PATH_APPEND']
|
||||
core_path.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
return core_path.resolve()
|
||||
Reference in New Issue
Block a user