aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl
diff options
context:
space:
mode:
authorWojtek Kosior <koszko@koszko.org>2022-08-23 09:26:16 +0200
committerWojtek Kosior <koszko@koszko.org>2022-09-28 12:54:52 +0200
commit5fefb11ffd50dcda826cd5a256c8b3f650221050 (patch)
treed98721a1b054b894e282668aea79157788903e73 /src/hydrilla/proxy/state_impl
parentc100476b0a34f5098efc96bf2487f09b66b4a6c4 (diff)
downloadhaketilo-hydrilla-5fefb11ffd50dcda826cd5a256c8b3f650221050.tar.gz
haketilo-hydrilla-5fefb11ffd50dcda826cd5a256c8b3f650221050.zip
introduce package installation state enum
Diffstat (limited to 'src/hydrilla/proxy/state_impl')
-rw-r--r--src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py7
-rw-r--r--src/hydrilla/proxy/state_impl/concrete_state.py2
-rw-r--r--src/hydrilla/proxy/state_impl/mappings.py178
-rw-r--r--src/hydrilla/proxy/state_impl/repos.py5
4 files changed, 144 insertions, 48 deletions
diff --git a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
index f83eb09..2b18a51 100644
--- a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
+++ b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
@@ -31,9 +31,12 @@
# Enable using with Python 3.7.
from __future__ import annotations
+import sqlite3
import typing as t
-import sqlite3
+from urllib.parse import urlparse, urljoin
+
+import requests
from .... import item_infos
from ... import simple_dependency_satisfying as sds
@@ -260,7 +263,7 @@ def _pull_missing_files(cursor: sqlite3.Cursor) -> None:
rows = cursor.fetchall()
- for file_id, sha56, repo_id, repo_url in rows:
+ for file_id, sha256, repo_id, repo_url in rows:
try:
response = requests.get(urljoin(repo_url, f'file/sha256/{sha256}'))
assert response.ok
diff --git a/src/hydrilla/proxy/state_impl/concrete_state.py b/src/hydrilla/proxy/state_impl/concrete_state.py
index fb4e2ca..ec16e11 100644
--- a/src/hydrilla/proxy/state_impl/concrete_state.py
+++ b/src/hydrilla/proxy/state_impl/concrete_state.py
@@ -147,7 +147,7 @@ class ConcreteHaketiloState(base.HaketiloStateWithFields):
return ConcreteRepoIterationRef(repo_iteration_id)
def mapping_store(self) -> st.MappingStore:
- raise NotImplementedError()
+ return mappings.ConcreteMappingStore(self)
def mapping_version_store(self) -> st.MappingVersionStore:
return mappings.ConcreteMappingVersionStore(self)
diff --git a/src/hydrilla/proxy/state_impl/mappings.py b/src/hydrilla/proxy/state_impl/mappings.py
index cce2a36..e5b324d 100644
--- a/src/hydrilla/proxy/state_impl/mappings.py
+++ b/src/hydrilla/proxy/state_impl/mappings.py
@@ -41,29 +41,28 @@ from . import base
@dc.dataclass(frozen=True, unsafe_hash=True)
-class ConcreteMappingVersionRef(st.MappingVersionRef):
- """...."""
+class ConcreteMappingRef(st.MappingRef):
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
- raise NotImplementedError()
-
- def get_display_info(self) -> st.MappingDisplayInfo:
+ def get_version_display_infos(self) \
+ -> t.Sequence[st.MappingVersionDisplayInfo]:
with self.state.cursor() as cursor:
cursor.execute(
'''
SELECT
- enabled,
+ item_version_id,
definition,
repo,
repo_iteration,
- is_orphan
+ installed,
+ is_active,
+ is_orphan,
+ is_local,
+ enabled
FROM
mapping_display_infos
WHERE
- item_version_id = ?;
+ item_id = ?;
''',
(self.id,)
)
@@ -73,61 +72,154 @@ class ConcreteMappingVersionRef(st.MappingVersionRef):
if rows == []:
raise st.MissingItemError()
- (status_letter, definition, repo, repo_iteration, is_orphan), = rows
+ result = []
- item_info = item_infos.MappingInfo.load(
- definition,
- repo,
- repo_iteration
- )
+ for (item_version_id, definition, repo, repo_iteration, installed,
+ is_active, is_orphan, is_local, status_letter) in rows:
+ ref = ConcreteMappingVersionRef(str(item_version_id), self.state)
- status = st.EnabledStatus(status_letter)
+ item_info = item_infos.MappingInfo.load(
+ definition,
+ repo,
+ repo_iteration
+ )
- return st.MappingDisplayInfo(self, item_info, status, is_orphan)
+ display_info = st.MappingVersionDisplayInfo(
+ ref = ref,
+ 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)
+ )
+ result.append(display_info)
+
+ return sorted(result, key=(lambda di: di.info))
@dc.dataclass(frozen=True)
-class ConcreteMappingVersionStore(st.MappingVersionStore):
+class ConcreteMappingStore(st.MappingStore):
state: base.HaketiloStateWithFields
- def get(self, id: str) -> st.MappingVersionRef:
- return ConcreteMappingVersionRef(id, self.state)
+ def get(self, id: str) -> st.MappingRef:
+ return ConcreteMappingRef(id, self.state)
- def get_display_infos(self) -> t.Iterable[st.MappingDisplayInfo]:
+ def get_display_infos(self) -> t.Sequence[st.MappingDisplayInfo]:
+ with self.state.cursor() as cursor:
+ cursor.execute(
+ '''
+ 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,
+ enabled
+ FROM
+ mapping_display_infos
+ WHERE
+ is_active OR item_version_id IS NULL;
+ '''
+ )
+
+ rows = cursor.fetchall()
+
+ result = []
+
+ for (item_id, identifier, item_version_id, definition, repo,
+ 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
+
+ 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(
+ definition,
+ repo,
+ repo_iteration
+ )
+
+ display_info = st.MappingDisplayInfo(
+ ref = ref,
+ identifier = identifier,
+ enabled = st.EnabledStatus(status_letter),
+ active_version_ref = active_version_ref,
+ active_version_info = item_info
+ )
+
+ result.append(display_info)
+
+ 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
+ raise NotImplementedError()
+
+ def get_display_info(self) -> st.MappingVersionDisplayInfo:
with self.state.cursor() as cursor:
cursor.execute(
'''
SELECT
- enabled,
- item_version_id,
definition,
repo,
repo_iteration,
- is_orphan
+ installed,
+ is_orphan,
+ is_active,
+ is_local,
+ enabled
FROM
- mapping_display_infos;
- '''
+ mapping_display_infos
+ WHERE
+ item_version_id = ?;
+ ''',
+ (self.id,)
)
- all_rows = cursor.fetchall()
+ rows = cursor.fetchall()
- result = []
+ if rows == []:
+ raise st.MissingItemError()
- for row in all_rows:
- (status_letter, item_version_id, definition, repo, repo_iteration,
- is_orphan) = row
+ (definition, repo, repo_iteration, installed, is_orphan, is_active,
+ is_local, status_letter), = rows
- ref = ConcreteMappingVersionRef(str(item_version_id), self.state)
+ item_info = item_infos.MappingInfo.load(
+ definition,
+ repo,
+ repo_iteration
+ )
- item_info = item_infos.MappingInfo.load(
- definition,
- repo,
- repo_iteration
- )
+ 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)
+ )
- status = st.EnabledStatus(status_letter)
- info = st.MappingDisplayInfo(ref, item_info, status, is_orphan)
- result.append(info)
+@dc.dataclass(frozen=True)
+class ConcreteMappingVersionStore(st.MappingVersionStore):
+ state: base.HaketiloStateWithFields
- return sorted(result, key=(lambda di: di.info))
+ def get(self, id: str) -> st.MappingVersionRef:
+ return ConcreteMappingVersionRef(id, self.state)
diff --git a/src/hydrilla/proxy/state_impl/repos.py b/src/hydrilla/proxy/state_impl/repos.py
index f4c7c71..663a450 100644
--- a/src/hydrilla/proxy/state_impl/repos.py
+++ b/src/hydrilla/proxy/state_impl/repos.py
@@ -35,7 +35,6 @@ from __future__ import annotations
import re
import json
import tempfile
-import requests
import sqlite3
import typing as t
import dataclasses as dc
@@ -44,6 +43,8 @@ from urllib.parse import urlparse, urljoin
from datetime import datetime
from pathlib import Path
+import requests
+
from ... import json_instances
from ... import item_infos
from ... import versions
@@ -349,7 +350,7 @@ class ConcreteRepoStore(st.RepoStore):
return ConcreteRepoRef(str(repo_id), self.state)
def get_display_infos(self, include_deleted: bool = False) \
- -> t.Iterable[st.RepoDisplayInfo]:
+ -> t.Sequence[st.RepoDisplayInfo]:
with self.state.cursor() as cursor:
condition: str = 'TRUE'
if include_deleted: