Skip to content

info_file_service

appimage_updater.core.info_file_service

Centralized .info file operations.

This module provides a single service for all .info file operations including finding, reading, and writing .info files consistently across the application.

InfoFileService

Centralized .info file operations.

find_info_file(app_config)

Find .info file using multiple strategies.

Priority: 1. Info file from .current files (rotation naming) 2. Any existing .info files in directory 3. Standard naming convention (fallback)

Returns:

Type Description
Path | None

Path to .info file if found, None if no suitable file exists

Source code in src/appimage_updater/core/info_file_service.py
def find_info_file(self, app_config: ApplicationConfig) -> Path | None:
    """Find .info file using multiple strategies.

    Priority:
    1. Info file from .current files (rotation naming)
    2. Any existing .info files in directory
    3. Standard naming convention (fallback)

    Returns:
        Path to .info file if found, None if no suitable file exists
    """
    download_dir = getattr(app_config, "download_dir", None) or Path.home() / "Downloads"

    if not download_dir.exists():
        return None

    return (
        self._strategy_1(download_dir)
        or self._strategy_2(download_dir)
        or self._strategy_3(download_dir, app_config)
    )

read_info_file(info_path)

Read and parse .info file content.

Parameters:

Name Type Description Default
info_path Path

Path to the .info file

required

Returns:

Type Description
str | None

Parsed version string or None if reading failed

Source code in src/appimage_updater/core/info_file_service.py
def read_info_file(self, info_path: Path) -> str | None:
    """Read and parse .info file content.

    Args:
        info_path: Path to the .info file

    Returns:
        Parsed version string or None if reading failed
    """
    if not info_path.exists():
        return None

    try:
        content = info_path.read_text().strip()
        return self._process_info_content(content)
    except (OSError, ValueError, AttributeError) as e:
        logger.debug(f"Failed to read info file {info_path}: {e}")
        return None

write_info_file(info_path, version)

Write version to .info file.

Parameters:

Name Type Description Default
info_path Path

Path where to write the .info file

required
version str

Version string to write

required

Returns:

Type Description
bool

True if successful, False otherwise

Source code in src/appimage_updater/core/info_file_service.py
def write_info_file(self, info_path: Path, version: str) -> bool:
    """Write version to .info file.

    Args:
        info_path: Path where to write the .info file
        version: Version string to write

    Returns:
        True if successful, False otherwise
    """
    try:
        # Ensure parent directory exists
        info_path.parent.mkdir(parents=True, exist_ok=True)

        # Write version with standard format
        content = f"Version: {version}"
        info_path.write_text(content)
        logger.debug(f"Wrote version '{version}' to info file: {info_path}")
        return True
    except (OSError, ValueError) as e:
        logger.error(f"Failed to write info file {info_path}: {e}")
        return False