deb-mock/deb_mock/plugins/__init__.py
robojerk 5e7f4b0562
Some checks failed
Build Deb-Mock Package / build (push) Successful in 55s
Lint Code / Lint All Code (push) Failing after 3s
Test Deb-Mock Build / test (push) Failing after 53s
Fix sbuild integration and clean up codebase
- Fix environment variable handling in sbuild wrapper
- Remove unsupported --log-dir and --env options from sbuild command
- Clean up unused imports and fix linting issues
- Organize examples directory with official Debian hello package
- Fix YAML formatting (trailing spaces, newlines)
- Remove placeholder example files
- All tests passing (30/30)
- Successfully tested build with official Debian hello package
2025-08-04 04:34:32 +00:00

91 lines
2.2 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 .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)