From 7fc6312d6df526b8eb49288aecf88d04668e7c45 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 29 Aug 2022 13:05:35 +0200 Subject: [proxy] make it possible to also view and install/uninstall libraries (resources) through the web UI --- src/hydrilla/item_infos.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/hydrilla/item_infos.py') 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) -- cgit v1.2.3