aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/item_infos.py
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-08-17 21:33:05 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-28 12:54:22 +0200
commita36677eb70b92cf64fccb16075b7fec55660157f (patch)
treea57b60853b0ad66ff3c233142c0431a5b1f5e05a /src/hydrilla/item_infos.py
parentd54a95e0f9c689f2bbaaea90a3a16a855a408823 (diff)
downloadhaketilo-hydrilla-a36677eb70b92cf64fccb16075b7fec55660157f.tar.gz
haketilo-hydrilla-a36677eb70b92cf64fccb16075b7fec55660157f.zip
bring Hydrilla server part back to a usable state
Diffstat (limited to 'src/hydrilla/item_infos.py')
-rw-r--r--src/hydrilla/item_infos.py265
1 files changed, 76 insertions, 189 deletions
diff --git a/src/hydrilla/item_infos.py b/src/hydrilla/item_infos.py
index a26e57a..a01fe3a 100644
--- a/src/hydrilla/item_infos.py
+++ b/src/hydrilla/item_infos.py
@@ -51,8 +51,6 @@ from .url_patterns import parse_pattern, ParsedUrl, ParsedPattern
from .exceptions import HaketiloException
from .translations import smart_gettext as _
-VerTuple = t.Tuple[int, ...]
-
@dc.dataclass(frozen=True, unsafe_hash=True)
class ItemSpecifier:
"""...."""
@@ -162,34 +160,15 @@ class ItemInfoBase(ABC, ItemIdentity, Categorizable):
required_mappings: tuple[ItemSpecifier, ...] = dc.field(hash=False, compare=False)
generated_by: t.Optional[GeneratedBy] = dc.field(hash=False, compare=False)
- # def path_relative_to_type(self) -> str:
- # """
- # Get a relative path to this item's JSON definition with respect to
- # directory containing items of this type.
- # """
- # return f'{self.identifier}/{versions.version_string(self.version)}'
-
- # def path(self) -> str:
- # """
- # Get a relative path to this item's JSON definition with respect to
- # malcontent directory containing loadable items.
- # """
- # return f'{self.type_name}/{self.path_relative_to_type()}'
-
- # @property
- # def identity(self):
- # """...."""
- # return ItemIdentity(
- # repository = self.repository,
- # version = self.version,
- # identifier = self.identifier
- # )
-
@property
- def versioned_identifier(self):
+ def versioned_identifier(self) -> str:
"""...."""
return f'{self.identifier}-{versions.version_string(self.version)}'
+ @property
+ def files(self) -> tuple[FileSpecifier, ...]:
+ return self.source_copyright
+
@staticmethod
def _get_base_init_kwargs(
item_obj: t.Mapping[str, t.Any],
@@ -242,9 +221,13 @@ class ResourceInfo(ItemInfoBase):
scripts: tuple[FileSpecifier, ...] = dc.field(hash=False, compare=False)
@property
- def versioned_identifier(self):
+ def versioned_identifier(self) -> str:
"""...."""
- return f'{super().versioned_identifier()}-{self.revision}'
+ return f'{super().versioned_identifier}-{self.revision}'
+
+ @property
+ def files(self) -> tuple[FileSpecifier, ...]:
+ return tuple((*self.source_copyright, *self.scripts))
@staticmethod
def make(
@@ -291,19 +274,6 @@ class ResourceInfo(ItemInfoBase):
repo_iteration
)
- # def __lt__(self, other: 'ResourceInfo') -> bool:
- # """...."""
- # return (
- # self.identifier,
- # self.version,
- # self.revision,
- # self.repository
- # ) < (
- # other.identifier,
- # other.version,
- # other.revision,
- # other.repository
- # )
def make_payloads(payloads_obj: t.Mapping[str, t.Any]) \
-> t.Mapping[ParsedPattern, ItemSpecifier]:
@@ -400,151 +370,68 @@ def _load_item_info(
)
-# CategorizedType = t.TypeVar(
-# 'CategorizedType',
-# bound=Categorizable
-# )
-
-# CategorizedUpdater = t.Callable[
-# [t.Optional[CategorizedType]],
-# t.Optional[CategorizedType]
-# ]
-
-# CategoryKeyType = t.TypeVar('CategoryKeyType', bound=t.Hashable)
-
-# @dc.dataclass(frozen=True)
-# class CategorizedItemInfo(Categorizable, t.Generic[CategorizedType, CategoryKeyType]):
-# """...."""
-# SelfType = t.TypeVar(
-# 'SelfType',
-# bound = 'CategorizedItemInfo[CategorizedType, CategoryKeyType]'
-# )
-
-# uuid: t.Optional[str] = None
-# identifier: str = '<dummy>'
-# items: Map[CategoryKeyType, CategorizedType] = Map()
-# _initialized: bool = False
-
-# def _update(
-# self: 'SelfType',
-# key: CategoryKeyType,
-# updater: CategorizedUpdater
-# ) -> 'SelfType':
-# """...... Perform sanity checks for uuid."""
-# uuid = self.uuid
-
-# items = self.items.mutate()
-
-# updated = updater(items.get(key))
-# if updated is None:
-# items.pop(key, None)
-
-# identifier = self.identifier
-# else:
-# items[key] = updated
-
-# identifier = updated.identifier
-# if self._initialized:
-# assert identifier == self.identifier
-
-# if uuid is not None:
-# if updated.uuid is not None and uuid != updated.uuid:
-# raise HaketiloException(_('uuid_mismatch_{identifier}')
-# .format(identifier=identifier))
-# else:
-# uuid = updated.uuid
-
-# return dc.replace(
-# self,
-# identifier = identifier,
-# uuid = uuid,
-# items = items.finish(),
-# _initialized = self._initialized or updated is not None
-# )
-
-# def is_empty(self) -> bool:
-# """...."""
-# return len(self.items) == 0
-
-
-# VersionedType = t.TypeVar('VersionedType', ResourceInfo, MappingInfo)
-
-# class VersionedItemInfo(
-# CategorizedItemInfo[VersionedType, VerTuple],
-# t.Generic[VersionedType]
-# ):
-# """Stores data of multiple versions of given resource/mapping."""
-# SelfType = t.TypeVar('SelfType', bound='VersionedItemInfo[VersionedType]')
-
-# def register(self: 'SelfType', item_info: VersionedType) -> 'SelfType':
-# """
-# Make item info queryable by version. Perform sanity checks for uuid.
-# """
-# return self._update(item_info.version, lambda old_info: item_info)
-
-# def unregister(self: 'SelfType', version: VerTuple) -> 'SelfType':
-# """...."""
-# return self._update(version, lambda old_info: None)
-
-# def newest_version(self) -> VerTuple:
-# """...."""
-# assert not self.is_empty()
-
-# return max(self.items.keys())
-
-# def get_newest(self) -> VersionedType:
-# """Find and return info of the newest version of item."""
-# newest = self.items[self.newest_version()]
-# assert newest is not None
-# return newest
-
-# def get_by_ver(self, ver: t.Iterable[int]) -> t.Optional[VersionedType]:
-# """
-# Find and return info of the specified version of the item (or None if
-# absent).
-# """
-# return self.items.get(tuple(ver))
-
-# def get_all(self) -> t.Iterator[VersionedType]:
-# """Generate item info for all its versions, from oldest to newest."""
-# for version in sorted(self.items.keys()):
-# yield self.items[version]
-
-
-# MultiRepoType = t.TypeVar('MultiRepoType', ResourceInfo, MappingInfo)
-# MultiRepoVersioned = VersionedItemInfo[MultiRepoType]
-
-# class MultiRepoItemInfo(
-# CategorizedItemInfo[MultiRepoVersioned, str],
-# t.Generic[MultiRepoType]
-# ):
-# SelfType = t.TypeVar('SelfType', bound='MultiRepoItemInfo[MultiRepoType]')
-
-# def register(self: 'SelfType', item_info: MultiRepoType) -> 'SelfType':
-# """
-# Make item info queryable by version. Perform sanity checks for uuid.
-# """
-# def updater(old_item: t.Optional[MultiRepoVersioned]) \
-# -> MultiRepoVersioned:
-# """...."""
-# if old_item is None:
-# old_item = VersionedItemInfo()
-
-# return old_item.register(item_info)
-
-# return self._update(item_info.repository, updater)
-
-# def unregister(self: 'SelfType', version: VerTuple, repository: str) \
-# -> 'SelfType':
-# """...."""
-# def updater(old_item: t.Optional[MultiRepoVersioned]) -> \
-# t.Optional[MultiRepoVersioned]:
-# """...."""
-# if old_item is None:
-# return None
-
-# new_item = old_item.unregister(version)
-
-# return None if new_item.is_empty() else new_item
-
-# return self._update(repository, updater)
+CategorizedType = t.TypeVar(
+ 'CategorizedType',
+ bound=Categorizable
+)
+
+CategorizedUpdater = t.Callable[
+ [t.Optional[CategorizedType]],
+ t.Optional[CategorizedType]
+]
+
+CategoryKeyType = t.TypeVar('CategoryKeyType', bound=t.Hashable)
+
+@dc.dataclass(frozen=True)
+class CategorizedItemInfo(Categorizable, t.Generic[CategorizedType, CategoryKeyType]):
+ """...."""
+ SelfType = t.TypeVar(
+ 'SelfType',
+ bound = 'CategorizedItemInfo[CategorizedType, CategoryKeyType]'
+ )
+
+ uuid: t.Optional[str] = None
+ identifier: str = '<dummy>'
+ items: Map[CategoryKeyType, CategorizedType] = Map()
+ _initialized: bool = False
+
+ def _update(
+ self: 'SelfType',
+ key: CategoryKeyType,
+ updater: CategorizedUpdater
+ ) -> 'SelfType':
+ """...... Perform sanity checks for uuid."""
+ uuid = self.uuid
+
+ items = self.items.mutate()
+
+ updated = updater(items.get(key))
+ if updated is None:
+ items.pop(key, None)
+
+ identifier = self.identifier
+ else:
+ items[key] = updated
+
+ identifier = updated.identifier
+ if self._initialized:
+ assert identifier == self.identifier
+
+ if uuid is not None:
+ if updated.uuid is not None and uuid != updated.uuid:
+ raise HaketiloException(_('uuid_mismatch_{identifier}')
+ .format(identifier=identifier))
+ else:
+ uuid = updated.uuid
+
+ return dc.replace(
+ self,
+ identifier = identifier,
+ uuid = uuid,
+ items = items.finish(),
+ _initialized = self._initialized or updated is not None
+ )
+
+ def is_empty(self) -> bool:
+ """...."""
+ return len(self.items) == 0