diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-25 10:18:33 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-09-09 13:55:05 +0200 |
commit | 2f2707ff2d19ad8c5aa6f626c65a9c298ff99901 (patch) | |
tree | c9d23bf7233e7cfaec1789bfca16f551a367b6b2 /src/hydrilla/proxy/state_impl/mappings.py | |
parent | aad33e091606555ef5989f88367b83851439e815 (diff) | |
download | haketilo-hydrilla-2f2707ff2d19ad8c5aa6f626c65a9c298ff99901.tar.gz haketilo-hydrilla-2f2707ff2d19ad8c5aa6f626c65a9c298ff99901.zip |
[proxy] make package version info page also display other versions; fix&improve some aspects of package loading and dependency recomputing
Diffstat (limited to 'src/hydrilla/proxy/state_impl/mappings.py')
-rw-r--r-- | src/hydrilla/proxy/state_impl/mappings.py | 155 |
1 files changed, 87 insertions, 68 deletions
diff --git a/src/hydrilla/proxy/state_impl/mappings.py b/src/hydrilla/proxy/state_impl/mappings.py index 946df14..7d08e58 100644 --- a/src/hydrilla/proxy/state_impl/mappings.py +++ b/src/hydrilla/proxy/state_impl/mappings.py @@ -51,19 +51,20 @@ class ConcreteMappingRef(st.MappingRef): cursor.execute( ''' SELECT - item_version_id, - definition, - repo, - repo_iteration, - installed, - is_active, - is_orphan, - is_local, - enabled + ive.item_version_id, + ive.definition, + ive.repo, + ive.repo_iteration, + ive.installed, + ive.active, + ive.is_orphan, + ive.is_local, + ms.enabled FROM - mapping_display_infos + item_versions_extra AS ive + JOIN mapping_statuses AS ms USING (item_id) WHERE - item_id = ?; + ive.item_id = ?; ''', (self.id,) ) @@ -75,8 +76,9 @@ class ConcreteMappingRef(st.MappingRef): result = [] - for (item_version_id, definition, repo, repo_iteration, installed, - is_active, is_orphan, is_local, status_letter) in rows: + for (item_version_id, definition, repo, repo_iteration, + installed_status, active_status, is_orphan, is_local, + enabled_status) in rows: ref = ConcreteMappingVersionRef(str(item_version_id), self.state) item_info = item_infos.MappingInfo.load( @@ -88,11 +90,11 @@ class ConcreteMappingRef(st.MappingRef): display_info = st.MappingVersionDisplayInfo( ref = ref, info = item_info, - installed = st.InstalledStatus(installed), - is_active = is_active, + installed = st.InstalledStatus(installed_status), + active = st.ActiveStatus(active_status), is_orphan = is_orphan, is_local = is_local, - mapping_enabled = st.EnabledStatus(status_letter) + mapping_enabled = st.EnabledStatus(enabled_status) ) result.append(display_info) @@ -104,22 +106,31 @@ class ConcreteMappingStore(st.MappingStore): state: base.HaketiloStateWithFields def get(self, id: str) -> st.MappingRef: - return ConcreteMappingRef(id, self.state) + return ConcreteMappingRef(str(int(id)), self.state) def get_display_infos(self) -> t.Sequence[st.MappingDisplayInfo]: with self.state.cursor() as cursor: cursor.execute( ''' - SELECT DISTINCT - item_id, - identifier, - CASE WHEN is_active THEN item_version_id ELSE NULL END, - CASE WHEN is_active THEN definition ELSE NULL END, - CASE WHEN is_active THEN repo ELSE NULL END, - CASE WHEN is_active THEN repo_iteration ELSE NULL END, - enabled + SELECT + i.item_id, + i.identifier, + ive.item_version_id, + ive.definition, + ive.repo, + ive.repo_iteration, + ive.installed, + ive.active, + ive.is_orphan, + ive.is_local, + ms.enabled FROM - mapping_display_infos; + items AS i + JOIN mapping_statuses AS ms + USING (item_id) + LEFT JOIN item_versions_extra AS ive + ON ms.active_version_id = ive.item_version_id AND + ive.active IN ('R', 'A'); ''' ) @@ -128,34 +139,45 @@ class ConcreteMappingStore(st.MappingStore): result = [] for (item_id, identifier, item_version_id, definition, repo, - repo_iteration, status_letter) in rows: + repo_iteration, installed_status, active_status, is_orphan, + is_local, enabled_status) in rows: ref = ConcreteMappingRef(str(item_id), self.state) - active_version_ref: t.Optional[st.MappingVersionRef] = None - item_info: t.Optional[item_infos.MappingInfo] = None + active_version: t.Optional[st.MappingVersionDisplayInfo] = None if item_version_id is not None: active_version_ref = ConcreteMappingVersionRef( id = str(item_version_id), state = self.state ) - item_info = item_infos.MappingInfo.load( + + active_version_info = item_infos.MappingInfo.load( definition, repo, repo_iteration ) + active_version = st.MappingVersionDisplayInfo( + ref = active_version_ref, + info = active_version_info, + installed = st.InstalledStatus(installed_status), + active = st.ActiveStatus(active_status), + is_orphan = is_orphan, + is_local = is_local, + mapping_enabled = st.EnabledStatus(enabled_status) + ) + + display_info = st.MappingDisplayInfo( - ref = ref, - identifier = identifier, - enabled = st.EnabledStatus(status_letter), - active_version_ref = active_version_ref, - active_version_info = item_info + ref = ref, + identifier = identifier, + enabled = st.EnabledStatus(enabled_status), + active_version = active_version ) result.append(display_info) - return result + return sorted(result, key=(lambda di: di.identifier)) @dc.dataclass(frozen=True, unsafe_hash=True) @@ -181,9 +203,26 @@ class ConcreteMappingVersionRef(st.MappingVersionRef): def install(self) -> None: with self.state.cursor(transaction=True) as cursor: - info = self.get_display_info() + cursor.execute( + ''' + SELECT + installed + FROM + item_versions + WHERE + item_version_id = ?; + ''', + (self.id,) + ) + + rows = cursor.fetchall() + + if rows == []: + raise st.MissingItemError() + + (installed_status,), = rows - if info.installed == st.InstalledStatus.INSTALLED: + if installed_status == 'I': return self._set_installed_status(cursor, st.InstalledStatus.INSTALLED) @@ -204,21 +243,15 @@ class ConcreteMappingVersionRef(st.MappingVersionRef): # # .... - def get_display_info(self) -> st.MappingVersionDisplayInfo: + def get_all_version_display_infos(self) \ + -> t.Sequence[st.MappingVersionDisplayInfo]: with self.state.cursor() as cursor: cursor.execute( ''' SELECT - definition, - repo, - repo_iteration, - installed, - is_orphan, - is_active, - is_local, - enabled + item_id FROM - mapping_display_infos + item_versions WHERE item_version_id = ?; ''', @@ -226,28 +259,14 @@ class ConcreteMappingVersionRef(st.MappingVersionRef): ) rows = cursor.fetchall() + if rows == []: + raise st.MissingItemError() - if rows == []: - raise st.MissingItemError() - - (definition, repo, repo_iteration, installed, is_orphan, is_active, - is_local, status_letter), = rows + (mapping_id,), = rows - item_info = item_infos.MappingInfo.load( - definition, - repo, - repo_iteration - ) + mapping_ref = ConcreteMappingRef(str(mapping_id), self.state) - return st.MappingVersionDisplayInfo( - ref = self, - info = item_info, - installed = st.InstalledStatus(installed), - is_active = is_active, - is_orphan = is_orphan, - is_local = is_local, - mapping_enabled = st.EnabledStatus(status_letter) - ) + return mapping_ref.get_version_display_infos() @dc.dataclass(frozen=True) @@ -255,4 +274,4 @@ class ConcreteMappingVersionStore(st.MappingVersionStore): state: base.HaketiloStateWithFields def get(self, id: str) -> st.MappingVersionRef: - return ConcreteMappingVersionRef(id, self.state) + return ConcreteMappingVersionRef(str(int(id)), self.state) |