86 lines
No EOL
2.3 KiB
Python
86 lines
No EOL
2.3 KiB
Python
"""
|
|
Deb-Mock Plugin System
|
|
|
|
This module provides the plugin system infrastructure for Deb-Mock,
|
|
inspired by Fedora's Mock plugin architecture but adapted for Debian-based systems.
|
|
"""
|
|
|
|
from .hook_manager import HookManager
|
|
from .base import BasePlugin
|
|
from .registry import PluginRegistry
|
|
|
|
# Global hook manager instance
|
|
hook_manager = HookManager()
|
|
|
|
# Global plugin registry
|
|
plugin_registry = PluginRegistry()
|
|
|
|
# Convenience function for plugins to register hooks
|
|
def add_hook(hook_name: str, callback):
|
|
"""
|
|
Register a hook callback.
|
|
|
|
This is the main interface for plugins to register hooks,
|
|
following the same pattern as Mock's plugin system.
|
|
|
|
Args:
|
|
hook_name: Name of the hook to register for
|
|
callback: Function to call when hook is triggered
|
|
"""
|
|
hook_manager.add_hook(hook_name, callback)
|
|
|
|
# Convenience function to call hooks
|
|
def call_hook(hook_name: str, context: dict = None):
|
|
"""
|
|
Call all registered hooks for a given hook name.
|
|
|
|
Args:
|
|
hook_name: Name of the hook to trigger
|
|
context: Context dictionary to pass to hook callbacks
|
|
"""
|
|
hook_manager.call_hook(hook_name, context)
|
|
|
|
# Convenience function to get available hooks
|
|
def get_hook_names() -> list:
|
|
"""
|
|
Get list of available hook names.
|
|
|
|
Returns:
|
|
List of hook names that have been registered
|
|
"""
|
|
return hook_manager.get_hook_names()
|
|
|
|
# Convenience function to register plugins
|
|
def register_plugin(plugin_name: str, plugin_class):
|
|
"""
|
|
Register a plugin class.
|
|
|
|
Args:
|
|
plugin_name: Name of the plugin
|
|
plugin_class: Plugin class to register
|
|
"""
|
|
plugin_registry.register(plugin_name, plugin_class)
|
|
|
|
# Convenience function to get registered plugins
|
|
def get_registered_plugins() -> dict:
|
|
"""
|
|
Get all registered plugins.
|
|
|
|
Returns:
|
|
Dictionary of registered plugin names and classes
|
|
"""
|
|
return plugin_registry.get_plugins()
|
|
|
|
# Convenience function to create plugin instances
|
|
def create_plugin(plugin_name: str, config):
|
|
"""
|
|
Create a plugin instance.
|
|
|
|
Args:
|
|
plugin_name: Name of the plugin to create
|
|
config: Configuration object
|
|
|
|
Returns:
|
|
Plugin instance
|
|
"""
|
|
return plugin_registry.create(plugin_name, config, hook_manager) |