diff options
author | Wojtek Kosior <koszko@koszko.org> | 2022-08-24 10:47:33 +0200 |
---|---|---|
committer | Wojtek Kosior <koszko@koszko.org> | 2022-09-28 12:54:53 +0200 |
commit | d516b9decad07b940b3cd117fc4e353dd8bbe7d2 (patch) | |
tree | 2ab6f78e067d88a9dce1043e496b1d5af283464b /src/hydrilla/proxy/state_impl/mappings.py | |
parent | 964bd44649aaf03c9afea06eadad0443032d8b77 (diff) | |
download | haketilo-hydrilla-d516b9decad07b940b3cd117fc4e353dd8bbe7d2.tar.gz haketilo-hydrilla-d516b9decad07b940b3cd117fc4e353dd8bbe7d2.zip |
make repo packages (mappings) load as uninstalled; make them installable through the web UI
Diffstat (limited to 'src/hydrilla/proxy/state_impl/mappings.py')
-rw-r--r-- | src/hydrilla/proxy/state_impl/mappings.py | 67 |
1 files changed, 50 insertions, 17 deletions
diff --git a/src/hydrilla/proxy/state_impl/mappings.py b/src/hydrilla/proxy/state_impl/mappings.py index e5b324d..946df14 100644 --- a/src/hydrilla/proxy/state_impl/mappings.py +++ b/src/hydrilla/proxy/state_impl/mappings.py @@ -31,13 +31,14 @@ This module provides an interface to interact with mappings inside Haketilo. # Enable using with Python 3.7. from __future__ import annotations -import io +import sqlite3 import typing as t import dataclasses as dc from ... import item_infos from .. import state as st from . import base +from . import _operations @dc.dataclass(frozen=True, unsafe_hash=True) @@ -112,19 +113,13 @@ class ConcreteMappingStore(st.MappingStore): SELECT DISTINCT item_id, identifier, - CASE WHEN enabled IN ('A', 'E') THEN item_version_id - ELSE NULL END, - CASE WHEN enabled IN ('A', 'E') THEN definition - ELSE NULL END, - CASE WHEN enabled IN ('A', 'E') THEN repo - ELSE NULL END, - CASE WHEN enabled IN ('A', 'E') THEN repo_iteration - ELSE NULL END, + 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 FROM - mapping_display_infos - WHERE - is_active OR item_version_id IS NULL; + mapping_display_infos; ''' ) @@ -136,8 +131,8 @@ class ConcreteMappingStore(st.MappingStore): repo_iteration, status_letter) in rows: ref = ConcreteMappingRef(str(item_id), self.state) - version_ref: t.Optional[st.MappingVersionRef] = None - item_info: t.Optional[item_infos.MappingInfo] = None + active_version_ref: t.Optional[st.MappingVersionRef] = None + item_info: t.Optional[item_infos.MappingInfo] = None if item_version_id is not None: active_version_ref = ConcreteMappingVersionRef( @@ -162,14 +157,52 @@ class ConcreteMappingStore(st.MappingStore): return result + @dc.dataclass(frozen=True, unsafe_hash=True) class ConcreteMappingVersionRef(st.MappingVersionRef): state: base.HaketiloStateWithFields = dc.field(hash=False, compare=False) - def update_status(self, new_status: st.EnabledStatus) -> None: - """....""" - assert new_status != st.EnabledStatus.AUTO_ENABLED + def _set_installed_status( + self, + cursor: sqlite3.Cursor, + new_status: st.InstalledStatus + ) -> None: + cursor.execute( + ''' + UPDATE + item_versions + SET + installed = ? + WHERE + item_version_id = ?; + ''', + (new_status.value, self.id,) + ) + + def install(self) -> None: + with self.state.cursor(transaction=True) as cursor: + info = self.get_display_info() + + if info.installed == st.InstalledStatus.INSTALLED: + return + + self._set_installed_status(cursor, st.InstalledStatus.INSTALLED) + + _operations.pull_missing_files(cursor) + + def uninstall(self) -> None: raise NotImplementedError() + # with self.state.cursor(transaction=True) as cursor: + # info = self.get_display_info() + + # if info.installed == st.InstalledStatus.NOT_INSTALLED: + # return + + # if info.installed == st.InstalledStatus.FAILED_TO_INSTALL: + # self._set_installed_status(st.InstalledStatus.UNINSTALLED) + # return + # + # .... def get_display_info(self) -> st.MappingVersionDisplayInfo: with self.state.cursor() as cursor: |