diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hydrilla/item_infos.py | 8 | ||||
-rw-r--r-- | src/hydrilla/proxy/state_impl/_operations/load_packages.py | 16 | ||||
-rw-r--r-- | src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py | 2 | ||||
-rw-r--r-- | src/hydrilla/server/malcontent.py | 19 |
4 files changed, 14 insertions, 31 deletions
diff --git a/src/hydrilla/item_infos.py b/src/hydrilla/item_infos.py index eb9a053..9a87b40 100644 --- a/src/hydrilla/item_infos.py +++ b/src/hydrilla/item_infos.py @@ -151,8 +151,6 @@ class ItemIdentity: @dc.dataclass(frozen=True) # type: ignore[misc] class ItemInfoBase(ABC, ItemIdentity, Categorizable): """....""" - type_name: t.ClassVar[str] - source_name: str = dc.field(hash=False, compare=False) source_copyright: tuple[FileSpecifier, ...] = dc.field(hash=False, compare=False) uuid: t.Optional[str] = dc.field(hash=False, compare=False) @@ -254,8 +252,6 @@ class CorrespondsToMappingDCMixin: @dc.dataclass(frozen=True, unsafe_hash=True) class ResourceInfo(ItemInfoBase, CorrespondsToResourceDCMixin): """....""" - type_name: t.ClassVar[str] = 'resource' - revision: int = dc.field(hash=False, compare=False) dependencies: tuple[ItemSpecifier, ...] = dc.field(hash=False, compare=False) scripts: tuple[FileSpecifier, ...] = dc.field(hash=False, compare=False) @@ -343,8 +339,6 @@ def make_payloads(payloads_obj: t.Mapping[str, t.Any]) \ @dc.dataclass(frozen=True, unsafe_hash=True) class MappingInfo(ItemInfoBase, CorrespondsToMappingDCMixin): """....""" - type_name: t.ClassVar[str] = 'mapping' - payloads: t.Mapping[ParsedPattern, ItemSpecifier] = \ dc.field(hash=False, compare=False) @@ -412,7 +406,7 @@ def _load_item_info( """Read, validate and autocomplete a mapping/resource description.""" instance = json_instances.read_instance(instance_source) - schema_fmt = f'api_{info_type.type_name}_description-{{}}.schema.json' + schema_fmt = f'api_{info_type.type.value}_description-{{}}.schema.json' schema_compat = json_instances.validate_instance(instance, schema_fmt) diff --git a/src/hydrilla/proxy/state_impl/_operations/load_packages.py b/src/hydrilla/proxy/state_impl/_operations/load_packages.py index f8fddfa..ca6baba 100644 --- a/src/hydrilla/proxy/state_impl/_operations/load_packages.py +++ b/src/hydrilla/proxy/state_impl/_operations/load_packages.py @@ -271,7 +271,7 @@ def _add_item( repo_iteration_id: int, repo_id: int ) -> None: - item_id = get_or_make_item(cursor, info.type_name, info.identifier) + item_id = get_or_make_item(cursor, info.type.value, info.identifier) if isinstance(info, item_infos.MappingInfo): make_mapping_status(cursor, item_id) @@ -343,9 +343,9 @@ AnyInfoVar = t.TypeVar( item_infos.MappingInfo ) -def _read_items(malcontent_path: Path, item_class: t.Type[AnyInfoVar]) \ +def _read_items(malcontent_path: Path, info_class: t.Type[AnyInfoVar]) \ -> t.Iterator[tuple[AnyInfoVar, bytes]]: - item_type_path = malcontent_path / item_class.type_name + item_type_path = malcontent_path / info_class.type.value if not item_type_path.is_dir(): return @@ -355,7 +355,7 @@ def _read_items(malcontent_path: Path, item_class: t.Type[AnyInfoVar]) \ for item_version_path in item_path.iterdir(): definition = item_version_path.read_bytes() - item_info = item_class.load(definition) + item_info = info_class.load(definition) assert item_info.identifier == item_path.name assert versions.version_string(item_info.version) == \ @@ -383,15 +383,11 @@ def _load_packages_no_state_update( repo_iteration_id = make_repo_iteration(cursor, repo_id) - types: t.Iterable[t.Type[item_infos.AnyInfo]] = \ - [item_infos.ResourceInfo, item_infos.MappingInfo] - - for info_type in types: + for type in [item_infos.ItemType.RESOURCE, item_infos.ItemType.MAPPING]: info: item_infos.AnyInfo - for info, definition in _read_items( # type: ignore malcontent_path, - info_type + type.info_class ): _add_item( cursor = cursor, diff --git a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py index 327a195..b62004c 100644 --- a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py +++ b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py @@ -62,7 +62,7 @@ def _get_infos_of_type(cursor: sqlite3.Cursor, info_type: t.Type[AnyInfoVar],) \ WHERE i.type = ?; ''', - (info_type.type_name[0].upper(),) + (info_type.type.value[0].upper(),) ) result: dict[int, AnyInfoVar] = {} diff --git a/src/hydrilla/server/malcontent.py b/src/hydrilla/server/malcontent.py index ce24330..af925a0 100644 --- a/src/hydrilla/server/malcontent.py +++ b/src/hydrilla/server/malcontent.py @@ -120,12 +120,8 @@ class Malcontent: fmt = _('err.server.malcontent_path_not_dir_{}') raise HaketiloException(fmt.format(malcontent_dir_path)) - types: t.Iterable[t.Type[item_infos.AnyInfo]] = ( - item_infos.MappingInfo, - item_infos.ResourceInfo - ) - for info_type in types: - type_path = self.malcontent_dir_path / info_type.type_name + for type in [item_infos.ItemType.RESOURCE, item_infos.ItemType.MAPPING]: + type_path = self.malcontent_dir_path / type.value if not type_path.is_dir(): continue @@ -135,7 +131,7 @@ class Malcontent: for ver_file in subpath.iterdir(): try: - self._load_item(info_type, ver_file) + self._load_item(type, ver_file) except: if self.werror: raise @@ -174,11 +170,8 @@ class Malcontent: versioned_info = infos.get(identifier, VersionedItemInfo()) infos[identifier] = versioned_info.register(item_info) - def _load_item( - self, - info_type: t.Type[item_infos.AnyInfo], - ver_file: Path - ) -> None: + def _load_item(self, type: item_infos.ItemType, ver_file: Path) \ + -> None: """ Reads, validates and autocompletes serveable mapping/resource definition, then registers information from it in data structures. @@ -186,7 +179,7 @@ class Malcontent: version = versions.parse(ver_file.name) identifier = ver_file.parent.name - item_info = info_type.load(ver_file) + item_info = type.info_class.load(ver_file) if item_info.identifier != identifier: fmt = _('err.server.item_{item}_in_file_{file}') |