Normalize names of attributes with Config instances (#3765)

* Lets normalize how we name config attributes across the bot.

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* ....

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>

* nothing to see here

Signed-off-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
Draper
2020-04-20 18:12:57 +01:00
committed by GitHub
parent df7ca65108
commit e4018ec677
22 changed files with 328 additions and 325 deletions

View File

@@ -40,9 +40,9 @@ class Downloader(commands.Cog):
super().__init__()
self.bot = bot
self.conf = Config.get_conf(self, identifier=998240343, force_registration=True)
self.config = Config.get_conf(self, identifier=998240343, force_registration=True)
self.conf.register_global(schema_version=0, installed_cogs={}, installed_libraries={})
self.config.register_global(schema_version=0, installed_cogs={}, installed_libraries={})
self.already_agreed = False
@@ -99,22 +99,22 @@ class Downloader(commands.Cog):
self._ready.set()
async def _maybe_update_config(self) -> None:
schema_version = await self.conf.schema_version()
schema_version = await self.config.schema_version()
if schema_version == 0:
await self._schema_0_to_1()
schema_version += 1
await self.conf.schema_version.set(schema_version)
await self.config.schema_version.set(schema_version)
async def _schema_0_to_1(self):
"""
This contains migration to allow saving state
of both installed cogs and shared libraries.
"""
old_conf = await self.conf.get_raw("installed", default=[])
old_conf = await self.config.get_raw("installed", default=[])
if not old_conf:
return
async with self.conf.installed_cogs() as new_cog_conf:
async with self.config.installed_cogs() as new_cog_conf:
for cog_json in old_conf:
repo_name = cog_json["repo_name"]
module_name = cog_json["cog_name"]
@@ -126,7 +126,7 @@ class Downloader(commands.Cog):
"commit": "",
"pinned": False,
}
await self.conf.clear_raw("installed")
await self.config.clear_raw("installed")
# no reliable way to get installed libraries (i.a. missing repo name)
# but it only helps `[p]cog update` run faster so it's not an issue
@@ -150,7 +150,7 @@ class Downloader(commands.Cog):
All installed cogs.
"""
installed = await self.conf.installed_cogs()
installed = await self.config.installed_cogs()
# noinspection PyTypeChecker
return tuple(
InstalledModule.from_json(cog_json, self._repo_manager)
@@ -167,7 +167,7 @@ class Downloader(commands.Cog):
All installed shared libraries.
"""
installed = await self.conf.installed_libraries()
installed = await self.config.installed_libraries()
# noinspection PyTypeChecker
return tuple(
InstalledModule.from_json(lib_json, self._repo_manager)
@@ -195,8 +195,8 @@ class Downloader(commands.Cog):
The modules to check off.
"""
installed_cogs = await self.conf.installed_cogs()
installed_libraries = await self.conf.installed_libraries()
installed_cogs = await self.config.installed_cogs()
installed_libraries = await self.config.installed_libraries()
for module in modules:
if module.type == InstallableType.COG:
installed = installed_cogs
@@ -208,8 +208,8 @@ class Downloader(commands.Cog):
repo_json = installed.setdefault(module.repo_name, {})
repo_json[module.name] = module_json
await self.conf.installed_cogs.set(installed_cogs)
await self.conf.installed_libraries.set(installed_libraries)
await self.config.installed_cogs.set(installed_cogs)
await self.config.installed_libraries.set(installed_libraries)
async def _remove_from_installed(self, modules: Iterable[InstalledModule]) -> None:
"""Remove modules from the saved list
@@ -221,8 +221,8 @@ class Downloader(commands.Cog):
The modules to remove.
"""
installed_cogs = await self.conf.installed_cogs()
installed_libraries = await self.conf.installed_libraries()
installed_cogs = await self.config.installed_cogs()
installed_libraries = await self.config.installed_libraries()
for module in modules:
if module.type == InstallableType.COG:
installed = installed_cogs
@@ -233,8 +233,8 @@ class Downloader(commands.Cog):
with contextlib.suppress(KeyError):
installed[module._json_repo_name].pop(module.name)
await self.conf.installed_cogs.set(installed_cogs)
await self.conf.installed_libraries.set(installed_libraries)
await self.config.installed_cogs.set(installed_cogs)
await self.config.installed_libraries.set(installed_libraries)
async def _shared_lib_load_check(self, cog_name: str) -> Optional[Repo]:
# remove in Red 3.4

View File

@@ -990,8 +990,8 @@ class RepoManager:
def __init__(self) -> None:
self._repos: Dict[str, Repo] = {}
self.conf = Config.get_conf(self, identifier=170708480, force_registration=True)
self.conf.register_global(repos={})
self.config = Config.get_conf(self, identifier=170708480, force_registration=True)
self.config.register_global(repos={})
async def initialize(self) -> None:
await self._load_repos(set_repos=True)
@@ -1040,7 +1040,7 @@ class RepoManager:
url=url, name=name, branch=branch, commit="", folder_path=self.repos_folder / name
)
await r.clone()
await self.conf.repos.set_raw(name, value=r.branch)
await self.config.repos.set_raw(name, value=r.branch)
self._repos[name] = r
@@ -1110,7 +1110,7 @@ class RepoManager:
safe_delete(repo.folder_path)
await self.conf.repos.clear_raw(repo.name)
await self.config.repos.clear_raw(repo.name)
try:
del self._repos[name]
except KeyError:
@@ -1189,10 +1189,10 @@ class RepoManager:
if not folder.is_dir():
continue
try:
branch = await self.conf.repos.get_raw(folder.stem, default="")
branch = await self.config.repos.get_raw(folder.stem, default="")
ret[folder.stem] = await Repo.from_folder(folder, branch)
if branch == "":
await self.conf.repos.set_raw(folder.stem, value=ret[folder.stem].branch)
await self.config.repos.set_raw(folder.stem, value=ret[folder.stem].branch)
except errors.NoRemoteURL:
log.warning("A remote URL does not exist for repo %s", folder.stem)
except errors.DownloaderException as err: