From 2579081df2a568192887d776a6965af323b7c4ee Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 18 Aug 2022 13:40:16 +0200 Subject: make it possible to list all repositories in the web UI --- src/hydrilla/proxy/state.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'src/hydrilla/proxy/state.py') diff --git a/src/hydrilla/proxy/state.py b/src/hydrilla/proxy/state.py index 14d38b6..c3712f2 100644 --- a/src/hydrilla/proxy/state.py +++ b/src/hydrilla/proxy/state.py @@ -39,6 +39,7 @@ import typing as t from pathlib import Path from abc import ABC, abstractmethod from enum import Enum +from datetime import datetime from immutables import Map @@ -68,6 +69,9 @@ class Ref: """....""" id: str + def __post_init__(self): + assert isinstance(self.id, str) + RefType = t.TypeVar('RefType', bound=Ref) @@ -83,14 +87,13 @@ class Store(ABC, t.Generic[RefType]): class RepoRef(Ref): """....""" @abstractmethod - def remove(self, state: 'HaketiloState') -> None: + def remove(self) -> None: """....""" ... @abstractmethod def update( self, - state: 'HaketiloState', *, name: t.Optional[str] = None, url: t.Optional[str] = None @@ -99,10 +102,30 @@ class RepoRef(Ref): ... @abstractmethod - def refresh(self, state: 'HaketiloState') -> 'RepoIterationRef': + def refresh(self) -> 'RepoIterationRef': """....""" ... + @abstractmethod + def get_display_info(self) -> 'RepoDisplayInfo': + ... + +@dc.dataclass(frozen=True) +class RepoDisplayInfo: + ref: RepoRef + name: str + url: t.Optional[str] + deleted: t.Optional[bool] + last_refreshed: t.Optional[datetime] + resource_count: int + mapping_count: int + +class RepoStore(Store[RepoRef]): + @abstractmethod + def get_display_infos(self, include_deleted: bool = False) -> \ + t.Iterable[RepoDisplayInfo]: + ... + @dc.dataclass(frozen=True, unsafe_hash=True) # type: ignore[misc] class RepoIterationRef(Ref): @@ -253,7 +276,7 @@ class HaketiloState(ABC): ... @abstractmethod - def get_repo(self, repo_id: str) -> RepoRef: + def repo_store(self) -> RepoStore: """....""" ... -- cgit v1.2.3