mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-12-16 20:23:41 +00:00
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
#
|
|
# Copyright (c) 2021-2023 ahriman team.
|
|
#
|
|
# This file is part of ahriman
|
|
# (see https://github.com/arcan1s/ahriman).
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
from ahriman.core.exceptions import InitializeError
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class RepositoryId:
|
|
"""
|
|
unique identifier of the repository
|
|
|
|
Attributes:
|
|
architecture(str): repository architecture
|
|
name(str): repository name
|
|
"""
|
|
|
|
architecture: str
|
|
name: str
|
|
|
|
def __post_init__(self) -> None:
|
|
"""
|
|
check that name is set
|
|
|
|
Raises:
|
|
InitializeError: in case if name is not set
|
|
"""
|
|
if not self.name:
|
|
raise InitializeError("Repository name is not set")
|
|
|
|
def __lt__(self, other: Any) -> bool:
|
|
"""
|
|
comparison operator for sorting
|
|
|
|
Args:
|
|
other(Any): other object to compare
|
|
|
|
Returns:
|
|
bool: True in case if this is less than other and False otherwise
|
|
|
|
Raises:
|
|
TypeError: if other is different from RepositoryId type
|
|
"""
|
|
if not isinstance(other, RepositoryId):
|
|
raise ValueError(f"'<' not supported between instances of '{type(self)}' and '{type(other)}'")
|
|
|
|
return self.name <= other.name and self.architecture < other.architecture
|