aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl/mappings.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/state_impl/mappings.py')
-rw-r--r--src/hydrilla/proxy/state_impl/mappings.py67
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: