diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-29 13:05:35 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-09-28 12:54:54 +0200 |
commit | 7fc6312d6df526b8eb49288aecf88d04668e7c45 (patch) | |
tree | bc9bda05270991892383839379c101515a440576 /src/hydrilla/item_infos.py | |
parent | 367ea85057368047a50ae98a3510e0113eadd744 (diff) | |
download | haketilo-hydrilla-7fc6312d6df526b8eb49288aecf88d04668e7c45.tar.gz haketilo-hydrilla-7fc6312d6df526b8eb49288aecf88d04668e7c45.zip |
[proxy] make it possible to also view and install/uninstall libraries (resources) through the web UI
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) |