"""Package model representing an RPM package.""" from dataclasses import dataclass from pathlib import Path from typing import Optional @dataclass class Package: """Represents an RPM package from a Rocky Linux repository. Attributes: name: Package name (e.g., 'bash') version: Package version release: Package release arch: Architecture (e.g., 'x86_64', 'noarch') repo_type: Repository type ('BaseOS' or 'AppStream') location: Relative path in repo (e.g., 'Packages/b/bash-5.1.8-6.el9.x86_64.rpm') baseurl: Base URL of the repository checksum: Package checksum for verification checksum_type: Type of checksum (e.g., 'sha256') download_path: Local path where package is downloaded has_manpages: Whether this package contains man pages """ name: str version: str release: str arch: str repo_type: str location: str baseurl: str checksum: str checksum_type: str has_manpages: bool = False download_path: Optional[Path] = None @property def filename(self) -> str: """Get the RPM filename from the location.""" return self.location.split("/")[-1] @property def download_url(self) -> str: """Get the full download URL for this package.""" return f"{self.baseurl.rstrip('/')}/{self.location.lstrip('/')}" @property def nvra(self) -> str: """Get the Name-Version-Release-Arch identifier.""" return f"{self.name}-{self.version}-{self.release}.{self.arch}" def __lt__(self, other): """Enable sorting packages by name.""" return self.name < other.name def __str__(self): return f"{self.nvra} ({self.repo_type})"