Skip to content

registry

appimage_updater.repositories.registry

Repository handler registry system for dynamic repository type discovery.

This module provides a plugin-like architecture for repository handlers, allowing new repository types to be added without modifying core code.

RepositoryHandler

Abstract base class for repository handlers.

metadata property

Get handler metadata.

can_handle_url(url) abstractmethod

Check if this handler can handle the given URL.

Source code in src/appimage_updater/repositories/registry.py
@abstractmethod
def can_handle_url(self, url: str) -> bool:
    """Check if this handler can handle the given URL."""
    pass

create_client(**kwargs) abstractmethod

Create a repository client instance.

Source code in src/appimage_updater/repositories/registry.py
@abstractmethod
def create_client(self, **kwargs: Any) -> RepositoryClient:
    """Create a repository client instance."""
    pass

RepositoryHandlerMetadata(name, priority=100, supported_domains=list(), supported_url_patterns=list(), description='', version='1.0.0') dataclass

Metadata for a repository handler.

description = '' class-attribute instance-attribute

name instance-attribute

priority = 100 class-attribute instance-attribute

supported_domains = field(default_factory=list) class-attribute instance-attribute

supported_url_patterns = field(default_factory=list) class-attribute instance-attribute

version = '1.0.0' class-attribute instance-attribute

can_handle_url_pattern(url)

Check if this handler can handle a URL pattern.

Source code in src/appimage_updater/repositories/registry.py
def can_handle_url_pattern(self, url: str) -> bool:
    """Check if this handler can handle a URL pattern."""
    return any(re.match(pattern, url, re.IGNORECASE) for pattern in self.supported_url_patterns)

RepositoryHandlerRegistry() cached

Registry for repository handlers with dynamic discovery.

Source code in src/appimage_updater/repositories/registry.py
def __init__(self) -> None:
    self._handlers: dict[str, RepositoryHandler] = {}
    self._initialized = False

get_handler(name)

Get a specific handler by name.

Source code in src/appimage_updater/repositories/registry.py
def get_handler(self, name: str) -> RepositoryHandler | None:
    """Get a specific handler by name."""
    self._ensure_initialized()
    return self._handlers.get(name)

get_handlers_for_url(url)

Get all handlers that can handle the given URL, sorted by priority.

Source code in src/appimage_updater/repositories/registry.py
def get_handlers_for_url(self, url: str) -> list[RepositoryHandler]:
    """Get all handlers that can handle the given URL, sorted by priority."""
    self._ensure_initialized()

    compatible_handlers = [handler for handler in self._handlers.values() if handler.can_handle_url(url)]

    # Sort by priority (lower numbers first)
    compatible_handlers.sort(key=lambda h: h.metadata.priority)
    return compatible_handlers

register(handler)

Register a repository handler.

Source code in src/appimage_updater/repositories/registry.py
def register(self, handler: RepositoryHandler) -> None:
    """Register a repository handler."""
    name = handler.metadata.name
    if name in self._handlers:
        logger.warning(f"Repository handler '{name}' is already registered, replacing")

    self._handlers[name] = handler
    logger.debug(f"Registered repository handler: {name} (priority: {handler.metadata.priority})")

get_repository_registry()

Get the global repository handler registry (cached).

Source code in src/appimage_updater/repositories/registry.py
def get_repository_registry() -> RepositoryHandlerRegistry:
    """Get the global repository handler registry (cached)."""
    return RepositoryHandlerRegistry()