diff options
Diffstat (limited to 'src/hydrilla/item_infos.py')
-rw-r--r-- | src/hydrilla/item_infos.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/src/hydrilla/item_infos.py b/src/hydrilla/item_infos.py index 2b89600..ddd1d80 100644 --- a/src/hydrilla/item_infos.py +++ b/src/hydrilla/item_infos.py @@ -38,6 +38,7 @@ if sys.version_info >= (3, 8): else: from typing_extensions import Protocol +import enum import typing as t import dataclasses as dc @@ -51,6 +52,7 @@ from .url_patterns import parse_pattern, ParsedUrl, ParsedPattern from .exceptions import HaketiloException from .translations import smart_gettext as _ + @dc.dataclass(frozen=True, unsafe_hash=True) class ItemSpecifier: """....""" @@ -274,6 +276,21 @@ class ResourceInfo(ItemInfoBase): repo_iteration ) + def __lt__(self, other: 'ResourceInfo') -> bool: + """....""" + return ( + self.identifier, + other.version, + other.revision, + self.repo, + other.repo_iteration + ) < ( + other.identifier, + self.version, + self.revision, + other.repo, + self.repo_iteration + ) def make_payloads(payloads_obj: t.Mapping[str, t.Any]) \ -> t.Mapping[ParsedPattern, ItemSpecifier]: @@ -346,6 +363,31 @@ class MappingInfo(ItemInfoBase): AnyInfo = t.Union[ResourceInfo, MappingInfo] +class ItemType(enum.Enum): + RESOURCE = 'resource' + MAPPING = 'mapping' + + @property + def info_class(self) -> t.Type[AnyInfo]: + if self == ItemType.RESOURCE: + return ResourceInfo + else: + return MappingInfo + + @property + def alt_name(self) -> str: + if self == ItemType.RESOURCE: + return 'library' + else: + return 'package' + + @property + def alt_name_plural(self) -> str: + if self == ItemType.RESOURCE: + return 'libraries' + else: + return 'packages' + LoadedType = t.TypeVar('LoadedType', ResourceInfo, MappingInfo) |