diff --git a/backup/backup.py b/backup/backup.py index 8c3b9c8..821ed0c 100644 --- a/backup/backup.py +++ b/backup/backup.py @@ -150,73 +150,72 @@ class Backup(commands.Cog): ) continue - else: - cog_modules = [] - for cog in cogs: - try: - cog_module = await InstalledCog.convert(ctx, cog['name']) - except commands.BadArgument: - uninstall_e.append(f"Failed to uninstall {cog['name']}") + cog_modules = [] + for cog in cogs: + try: + cog_module = await InstalledCog.convert(ctx, cog['name']) + except commands.BadArgument: + uninstall_e.append(f"Failed to uninstall {cog['name']}") + continue + cog_modules.append(cog_module) + + for cog in set(cog.name for cog in cog_modules): + poss_installed_path = (await downloader.cog_install_path()) / cog + if poss_installed_path.exists(): + 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) # pylint: disable=protected-access + uninstall_s.append(f"Uninstalled {cog}") + else: + uninstall_e.append(f"Failed to uninstall {cog}") + await downloader._remove_from_installed(cog_modules) # pylint: disable=protected-access + + for cog in cogs: + cog_name = cog['name'] + cog_pinned = cog['pinned'] + if cog_pinned: + commit = cog['commit'] + else: + commit = None + + # If you're forking this cog, make sure to change these strings! + if cog_name == 'backup' and 'SeaswimmerTheFsh/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]) # pylint: disable=protected-access + if not cogs_c: + install_e.append(message) + continue + failed_reqs = await downloader._install_requirements(cogs_c) # pylint: disable=protected-access + if failed_reqs: + install_e.append(f"Failed to install {cog_name} due to missing requirements: {failed_reqs}") continue - cog_modules.append(cog_module) - for cog in set(cog.name for cog in cog_modules): - poss_installed_path = (await downloader.cog_install_path()) / cog - if poss_installed_path.exists(): - 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) # pylint: disable=protected-access - uninstall_s.append(f"Uninstalled {cog}") + installed_cogs, failed_cogs = await downloader._install_cogs(cogs_c) # pylint: disable=protected-access + + if repository.available_libraries: + installed_libs, failed_libs = await repository.install_libraries(target_dir=downloader.SHAREDLIB_PATH, req_target_dir=downloader.LIB_PATH) else: - uninstall_e.append(f"Failed to uninstall {cog}") - await downloader._remove_from_installed(cog_modules) # pylint: disable=protected-access + installed_libs = None + failed_libs = None - for cog in cogs: - cog_name = cog['name'] - cog_pinned = cog['pinned'] if cog_pinned: - commit = cog['commit'] - else: - commit = None + for cog in installed_cogs: + cog.pinned = True - # If you're forking this cog, make sure to change these strings! - if cog_name == 'backup' and 'SeaswimmerTheFsh/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]) # pylint: disable=protected-access - if not cogs_c: - install_e.append(message) - continue - failed_reqs = await downloader._install_requirements(cogs_c) # pylint: disable=protected-access - if failed_reqs: - install_e.append(f"Failed to install {cog_name} due to missing requirements: {failed_reqs}") - continue - - installed_cogs, failed_cogs = await downloader._install_cogs(cogs_c) # pylint: disable=protected-access - - if repository.available_libraries: - 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: - cog.pinned = True - - await downloader._save_to_installed(installed_cogs + installed_libs if installed_libs else installed_cogs) # pylint: disable=protected-access - if installed_cogs: - installed_cog_name = installed_cogs[0].name - install_s.append(f"Installed {installed_cog_name}") - if installed_libs: - for lib in installed_libs: - install_s.append(f"Installed {lib.name} required for {cog_name}") - if failed_cogs: - failed_cog_name = failed_cogs[0].name - install_e.append(f"Failed to install {failed_cog_name}") - if failed_libs: - for lib in failed_libs: - install_e.append(f"Failed to install {lib.name} required for {cog_name}") + await downloader._save_to_installed(installed_cogs + installed_libs if installed_libs else installed_cogs) # pylint: disable=protected-access + if installed_cogs: + installed_cog_name = installed_cogs[0].name + install_s.append(f"Installed {installed_cog_name}") + if installed_libs: + for lib in installed_libs: + install_s.append(f"Installed {lib.name} required for {cog_name}") + if failed_cogs: + failed_cog_name = failed_cogs[0].name + install_e.append(f"Failed to install {failed_cog_name}") + if failed_libs: + for lib in failed_libs: + install_e.append(f"Failed to install {lib.name} required for {cog_name}") await ctx.send("Import complete!", file=text_to_file(f"Repositories:\n{repo_s}\n\nRepository Errors:\n{repo_e}\n\nUninstalled Cogs:\n{uninstall_s}\n\nUninstalled Cogs Errors:\n{uninstall_e}\n\nInstalled Cogs:\n{install_s}\n\nInstalled Cogs Errors:\n{install_e}", 'backup.log'))