From 0c43e3d2c95316c68be4beb37b0799db3e3789ec Mon Sep 17 00:00:00 2001 From: cswimr Date: Sun, 26 Jan 2025 13:21:28 +0000 Subject: [PATCH] fix(backup): update for red 3.5.14 & reformat --- backup/backup.py | 108 ++++++++++++----------------------------------- backup/info.json | 22 ++++++---- 2 files changed, 41 insertions(+), 89 deletions(-) diff --git a/backup/backup.py b/backup/backup.py index dfc5397..4ba184f 100644 --- a/backup/backup.py +++ b/backup/backup.py @@ -23,7 +23,7 @@ class Backup(commands.Cog): __author__ = ["[cswimr](https://www.coastalcommits.com/cswimr)"] __git__ = "https://www.coastalcommits.com/cswimr/SeaCogs" - __version__ = "1.1.1" + __version__ = "1.1.2" __documentation__ = "https://seacogs.coastalcommits.com/backup/" def __init__(self, bot: Red): @@ -53,11 +53,7 @@ class Backup(commands.Cog): """Export your installed repositories and cogs to a file.""" downloader = ctx.bot.get_cog("Downloader") if downloader is None: - await ctx.send( - error( - f"You do not have the `Downloader` cog loaded. Please run `{ctx.prefix}load downloader` and try again." - ) - ) + await ctx.send(error(f"You do not have the `Downloader` cog loaded. Please run `{ctx.prefix}load downloader` and try again.")) return all_repos = list(downloader._repo_manager.repos) @@ -88,9 +84,7 @@ class Backup(commands.Cog): export_data.append(repo_dict) - await ctx.send( - file=text_to_file(json.dumps(export_data, indent=4), "backup.json") - ) + await ctx.send(file=text_to_file(json.dumps(export_data, indent=4), "backup.json")) @backup.command(name="import") @commands.is_owner() @@ -107,11 +101,7 @@ class Backup(commands.Cog): downloader = ctx.bot.get_cog("Downloader") if downloader is None: - await ctx.send( - error( - f"You do not have the `Downloader` cog loaded. Please run `{ctx.prefix}load downloader` and try again." - ) - ) + await ctx.send(error(f"You do not have the `Downloader` cog loaded. Please run `{ctx.prefix}load downloader` and try again.")) return repo_s = [] @@ -133,32 +123,20 @@ class Backup(commands.Cog): repo_e.append("PyLav cogs are not supported.") continue if name.startswith(".") or name.endswith("."): - repo_e.append( - f"Invalid repository name: {name}\nRepository names cannot start or end with a dot." - ) + repo_e.append(f"Invalid repository name: {name}\nRepository names cannot start or end with a dot.") continue if re.match(r"^[a-zA-Z0-9_\-\.]+$", name) is None: - repo_e.append( - f"Invalid repository name: {name}\nRepository names may only contain letters, numbers, underscores, hyphens, and dots." - ) + repo_e.append(f"Invalid repository name: {name}\nRepository names may only contain letters, numbers, underscores, hyphens, and dots.") continue try: - repository = await downloader._repo_manager.add_repo( - url, name, branch - ) - repo_s.append( - f"Added repository {name} from {url} on branch {branch}." - ) - self.logger.debug( - "Added repository %s from %s on branch %s", name, url, branch - ) + repository = await downloader._repo_manager.add_repo(url, name, branch) + repo_s.append(f"Added repository {name} from {url} on branch {branch}.") + self.logger.debug("Added repository %s from %s on branch %s", name, url, branch) except errors.ExistingGitRepo: repo_e.append(f"Repository {name} already exists.") - repository = downloader._repo_manager.get_repo( - name - ) + repository = downloader._repo_manager.get_repo(name) self.logger.debug("Repository %s already exists", name) except errors.AuthenticationError as err: @@ -172,9 +150,7 @@ class Backup(commands.Cog): continue except errors.CloningError as err: - repo_e.append( - f"Cloning error while adding repository {name}. See logs for more information." - ) + repo_e.append(f"Cloning error while adding repository {name}. See logs for more information.") self.logger.exception( "Something went wrong whilst cloning %s (to revision %s)", url, @@ -184,9 +160,7 @@ class Backup(commands.Cog): continue except OSError: - repo_e.append( - f"OS error while adding repository {name}. See logs for more information." - ) + repo_e.append(f"OS error while adding repository {name}. See logs for more information.") self.logger.exception( "Something went wrong trying to add repo %s under name %s", url, @@ -212,17 +186,13 @@ class Backup(commands.Cog): with contextlib.suppress(commands.ExtensionNotLoaded): await ctx.bot.unload_extension(cog) await ctx.bot.remove_loaded_package(cog) - await downloader._delete_cog( - poss_installed_path - ) + await downloader._delete_cog(poss_installed_path) uninstall_s.append(f"Uninstalled {cog}") self.logger.debug("Uninstalled %s", cog) else: uninstall_e.append(f"Failed to uninstall {cog}") self.logger.warning("Failed to uninstall %s", cog) - await downloader._remove_from_installed( - cog_modules - ) + await downloader._remove_from_installed(cog_modules) for cog in cogs: cog_name = cog["name"] @@ -236,25 +206,15 @@ class Backup(commands.Cog): if cog_name == "backup" and "cswimr/SeaCogs" in url: continue - async with repository.checkout( - commit, exit_to_rev=repository.branch - ): - cogs_c, message = ( - await downloader._filter_incorrect_cogs_by_names( - repository, [cog_name] - ) - ) + async with repository.checkout(commit, exit_to_rev=repository.branch): + cogs_c, message = await downloader._filter_incorrect_cogs_by_names(repository, [cog_name]) if not cogs_c: install_e.append(message) self.logger.error(message) continue - failed_reqs = await downloader._install_requirements( - cogs_c - ) + failed_reqs = await downloader._install_requirements(cogs_c) if failed_reqs: - install_e.append( - f"Failed to install {cog_name} due to missing requirements: {failed_reqs}" - ) + install_e.append(f"Failed to install {cog_name} due to missing requirements: {failed_reqs}") self.logger.error( "Failed to install %s due to missing requirements: %s", cog_name, @@ -262,51 +222,37 @@ class Backup(commands.Cog): ) continue - installed_cogs, failed_cogs = await downloader._install_cogs( - cogs_c - ) + installed_cogs, failed_cogs = await downloader._install_cogs(cogs_c) if repository.available_libraries: - installed_libs, failed_libs = ( - await repository.install_libraries( - target_dir=downloader.SHAREDLIB_PATH, - req_target_dir=downloader.LIB_PATH, - ) + installed_libs, failed_libs = await repository.install_libraries( + target_dir=downloader.SHAREDLIB_PATH, + req_target_dir=downloader.LIB_PATH, ) else: installed_libs = None failed_libs = None if cog_pinned: - for cog in installed_cogs: + for cog in installed_cogs: # noqa: PLW2901 cog.pinned = True - await downloader._save_to_installed( - installed_cogs + installed_libs - if installed_libs - else installed_cogs - ) + await downloader._save_to_installed(installed_cogs + installed_libs if installed_libs else installed_cogs) if installed_cogs: installed_cog_name = installed_cogs[0].name install_s.append(f"Installed {installed_cog_name}") self.logger.debug("Installed %s", installed_cog_name) if installed_libs: for lib in installed_libs: - install_s.append( - f"Installed {lib.name} required for {cog_name}" - ) - self.logger.debug( - "Installed %s required for %s", lib.name, cog_name - ) + install_s.append(f"Installed {lib.name} required for {cog_name}") + self.logger.debug("Installed %s required for %s", lib.name, cog_name) if failed_cogs: failed_cog_name = failed_cogs[0].name install_e.append(f"Failed to install {failed_cog_name}") self.logger.error("Failed to install %s", failed_cog_name) if failed_libs: for lib in failed_libs: - install_e.append( - f"Failed to install {lib.name} required for {cog_name}" - ) + install_e.append(f"Failed to install {lib.name} required for {cog_name}") self.logger.error( "Failed to install %s required for %s", lib.name, diff --git a/backup/info.json b/backup/info.json index 2e465b0..288ece1 100644 --- a/backup/info.json +++ b/backup/info.json @@ -1,15 +1,21 @@ { - "author" : ["cswimr"], - "install_msg" : "Thank you for installing Backup!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).", - "name" : "Backup", - "short" : "A utility to make reinstalling repositories and cogs after migrating the bot far easier.", - "description" : "A utility to make reinstalling repositories and cogs after migrating the bot far easier.", - "end_user_data_statement" : "This cog does not store end user data.", + "author": [ + "cswimr" + ], + "install_msg": "Thank you for installing Backup!\nYou can find the source code of this cog [here](https://coastalcommits.com/cswimr/SeaCogs).", + "name": "Backup", + "short": "A utility to make reinstalling repositories and cogs after migrating the bot far easier.", + "description": "A utility to make reinstalling repositories and cogs after migrating the bot far easier.", + "end_user_data_statement": "This cog does not store end user data.", "hidden": false, "disabled": false, "min_bot_version": "3.5.6", - "max_bot_version": "3.5.13", - "min_python_version": [3, 9, 0], + "max_bot_version": "3.5.14", + "min_python_version": [ + 3, + 9, + 0 + ], "tags": [ "utility", "backup",