From 824b8870e1e1c3cf433ce5c3b8cbda0330358c97 Mon Sep 17 00:00:00 2001 From: pacnpal <183241239+pacnpal@users.noreply.github.com> Date: Sun, 17 Nov 2024 00:07:43 +0000 Subject: [PATCH] Update root __init__.py: - Add module reloading to ensure exceptions are available - Import and re-export all necessary exceptions - Maintain existing setup and teardown functions - Add version information - Update __all__ list with all exports --- videoarchiver/__init__.py | 75 ++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 16 deletions(-) diff --git a/videoarchiver/__init__.py b/videoarchiver/__init__.py index 4404e96..443c2d1 100644 --- a/videoarchiver/__init__.py +++ b/videoarchiver/__init__.py @@ -1,14 +1,37 @@ """VideoArchiver cog for Red-DiscordBot""" +import sys import asyncio import logging +import importlib from typing import Optional from redbot.core.bot import Red +# Remove modules to force reload +modules_to_reload = [ + 'videoarchiver.utils.exceptions', + 'videoarchiver.utils' +] +for module in modules_to_reload: + if module in sys.modules: + del sys.modules[module] + +# Import and reload utils +from . import utils +importlib.reload(utils) + from .core.base import VideoArchiver from .core.initialization import initialize_cog, init_callback from .core.cleanup import cleanup_resources -from .exceptions import ProcessingError +from .utils.exceptions import ( + VideoArchiverError, + CommandError, + EventError, + CogError, + ErrorContext, + ErrorSeverity, + ProcessingError +) from .database import VideoArchiveDB from .ffmpeg import FFmpegManager from .queue import EnhancedVideoQueueManager @@ -21,55 +44,75 @@ logger = logging.getLogger("VideoArchiver") # Track initialization task _init_task: Optional[asyncio.Task] = None +# Version information +__version__ = "1.0.0" +__author__ = "VideoArchiver Team" +__description__ = "Video archiving cog for Red-DiscordBot" + async def setup(bot: Red) -> None: """Load VideoArchiver with proper initialization.""" try: # Create cog instance cog = VideoArchiver(bot) - + # Start initialization in background global _init_task _init_task = asyncio.create_task(initialize_cog(cog)) _init_task.add_done_callback(lambda t: init_callback(cog, t)) - + # Add cog to bot await bot.add_cog(cog) - + logger.info("VideoArchiver cog loaded successfully") - + except Exception as e: logger.error(f"Failed to load VideoArchiver: {str(e)}") if _init_task and not _init_task.done(): _init_task.cancel() raise + async def teardown(bot: Red) -> None: """Clean up when unloading.""" try: # Cancel initialization if still running if _init_task and not _init_task.done(): _init_task.cancel() - + # Remove cog and clean up resources if "VideoArchiver" in bot.cogs: cog = bot.get_cog("VideoArchiver") if cog: await cleanup_resources(cog) await bot.remove_cog("VideoArchiver") - + logger.info("VideoArchiver cog unloaded successfully") - + except Exception as e: logger.error(f"Error during teardown: {str(e)}") raise + __all__ = [ - 'VideoArchiver', - 'VideoArchiveDB', - 'FFmpegManager', - 'EnhancedVideoQueueManager', - 'VideoProcessor', - 'ConfigManager', - 'UpdateChecker', - 'ProcessingError' + # Core classes + "VideoArchiver", + "VideoArchiveDB", + "FFmpegManager", + "EnhancedVideoQueueManager", + "VideoProcessor", + "ConfigManager", + "UpdateChecker", + + # Base exceptions + "VideoArchiverError", + "CommandError", + "EventError", + "CogError", + "ErrorContext", + "ErrorSeverity", + "ProcessingError", + + # Setup functions + "setup", + "teardown" ]