Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add data_manager.instance_name() public API #6146

Merged
merged 1 commit into from
May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion redbot/cogs/audio/core/tasks/lavalink.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def lavalink_attempt_connect(self, timeout: int = 50, manual: bool = False
password=password,
port=port,
timeout=timeout,
resume_key=f"Red-Core-Audio-{self.bot.user.id}-{data_manager.instance_name}",
resume_key=f"Red-Core-Audio-{self.bot.user.id}-{data_manager.instance_name()}",
secured=secured,
)
except lavalink.AbortingNodeConnection:
Expand Down
5 changes: 3 additions & 2 deletions redbot/core/_debuginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ def _get_os_variables_section(self) -> DebugInfoSection:
)

async def _get_red_vars_section(self) -> DebugInfoSection:
if data_manager.instance_name is None:
instance_name = data_manager.instance_name()
if instance_name is None:
return DebugInfoSection(
"Red variables",
f"Metadata file: {data_manager.config_file}",
)

parts = [f"Instance name: {data_manager.instance_name}"]
parts = [f"Instance name: {instance_name}"]
if self.bot is not None:
owners = []
for uid in self.bot.owner_ids:
Expand Down
22 changes: 17 additions & 5 deletions redbot/core/data_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,17 @@
"core_data_path",
"bundled_data_path",
"data_path",
"instance_name",
"metadata_file",
"storage_details",
"storage_type",
"storage_details",
)

log = logging.getLogger("red.data_manager")

basic_config = None

instance_name = None
_instance_name = None

basic_config_default: Dict[str, Any] = {
"DATA_PATH": None,
Expand Down Expand Up @@ -106,8 +107,8 @@ def load_basic_configuration(instance_name_: str):
redbot setup.
"""
global basic_config
global instance_name
instance_name = instance_name_
global _instance_name
_instance_name = instance_name_

try:
with config_file.open(encoding="utf-8") as fs:
Expand All @@ -119,7 +120,7 @@ def load_basic_configuration(instance_name_: str):
)
sys.exit(ExitCodes.CONFIGURATION_ERROR)
try:
basic_config = config[instance_name]
basic_config = config[_instance_name]
except KeyError:
print(
"Instance with this name doesn't exist."
Expand Down Expand Up @@ -234,6 +235,17 @@ def data_path() -> Path:
return _base_data_path()


def instance_name() -> str:
"""Gets instance's name.

Returns
-------
str
Instance name.
"""
return _instance_name


def metadata_file() -> Path:
"""Gets the path of metadata file.

Expand Down
4 changes: 2 additions & 2 deletions redbot/core/utils/_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ async def create_backup(dest: Path = Path.home()) -> Optional[Path]:

dest.mkdir(parents=True, exist_ok=True)
timestr = datetime.utcnow().strftime("%Y-%m-%dT%H-%M-%S")
backup_fpath = dest / f"redv3_{data_manager.instance_name}_{timestr}.tar.gz"
backup_fpath = dest / f"redv3_{data_manager.instance_name()}_{timestr}.tar.gz"

to_backup = []
exclusions = [
Expand All @@ -242,7 +242,7 @@ async def create_backup(dest: Path = Path.home()) -> Optional[Path]:
json.dump(repo_output, fs, indent=4)
instance_file = data_path / "instance.json"
with instance_file.open("w") as fs:
json.dump({data_manager.instance_name: data_manager.basic_config}, fs, indent=4)
json.dump({data_manager.instance_name(): data_manager.basic_config}, fs, indent=4)
for f in data_path.glob("**/*"):
if not any(ex in str(f) for ex in exclusions) and f.is_file():
to_backup.append(f)
Expand Down