aboutsummaryrefslogtreecommitdiff
path: root/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py')
-rw-r--r--src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py78
1 files changed, 74 insertions, 4 deletions
diff --git a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
index 4093f12..f83eb09 100644
--- a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
+++ b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py
@@ -37,6 +37,7 @@ import sqlite3
from .... import item_infos
from ... import simple_dependency_satisfying as sds
+from ... import state
AnyInfoVar = t.TypeVar(
@@ -45,7 +46,7 @@ AnyInfoVar = t.TypeVar(
item_infos.MappingInfo
)
-def get_infos_of_type(cursor: sqlite3.Cursor, info_type: t.Type[AnyInfoVar],) \
+def _get_infos_of_type(cursor: sqlite3.Cursor, info_type: t.Type[AnyInfoVar],) \
-> t.Mapping[int, AnyInfoVar]:
cursor.execute(
'''
@@ -70,14 +71,27 @@ def get_infos_of_type(cursor: sqlite3.Cursor, info_type: t.Type[AnyInfoVar],) \
return result
-def _recompute_dependencies_no_state_update(
+def _mark_version_installed(cursor: sqlite3.Cursor, version_id: int) -> None:
+ cursor.execute(
+ '''
+ UPDATE
+ item_versions
+ SET
+ installed = 'I'
+ WHERE
+ item_version_id = ?;
+ ''',
+ (version_id,)
+ )
+
+def _recompute_dependencies_no_state_update_no_pull_files(
cursor: sqlite3.Cursor,
extra_requirements: t.Iterable[sds.MappingRequirement]
) -> None:
cursor.execute('DELETE FROM payloads;')
- ids_to_resources = get_infos_of_type(cursor, item_infos.ResourceInfo)
- ids_to_mappings = get_infos_of_type(cursor, item_infos.MappingInfo)
+ ids_to_resources = _get_infos_of_type(cursor, item_infos.ResourceInfo)
+ ids_to_mappings = _get_infos_of_type(cursor, item_infos.MappingInfo)
resources = ids_to_resources.items()
resources_to_ids = dict((info.identifier, id) for id, info in resources)
@@ -148,6 +162,8 @@ def _recompute_dependencies_no_state_update(
for choice in mapping_choices.values():
mapping_ver_id = mappings_to_ids[choice.info.identifier]
+ _mark_version_installed(cursor, mapping_ver_id)
+
cursor.execute(
'''
SELECT
@@ -210,6 +226,9 @@ def _recompute_dependencies_no_state_update(
for res_num, resource_info in enumerate(payload.resources):
resource_ver_id = resources_to_ids[resource_info.identifier]
+
+ _mark_version_installed(cursor, resource_ver_id)
+
cursor.execute(
'''
INSERT INTO resolved_depended_resources(
@@ -221,3 +240,54 @@ def _recompute_dependencies_no_state_update(
''',
(payload_id, resource_ver_id, res_num)
)
+
+def _pull_missing_files(cursor: sqlite3.Cursor) -> None:
+ cursor.execute(
+ '''
+ SELECT DISTINCT
+ f.file_id, f.sha256,
+ r.repo_id, r.url
+ FROM
+ repos AS R
+ JOIN repo_iterations AS ri USING (repo_id)
+ JOIN item_versions AS iv USING (repo_iteration_id)
+ JOIN file_uses AS fu USING (item_version_id)
+ JOIN files AS f USING (file_id)
+ WHERE
+ iv.installed = 'I' AND f.data IS NULL;
+ '''
+ )
+
+ rows = cursor.fetchall()
+
+ for file_id, sha56, repo_id, repo_url in rows:
+ try:
+ response = requests.get(urljoin(repo_url, f'file/sha256/{sha256}'))
+ assert response.ok
+ except:
+ raise state.FileInstallationError(
+ repo_id = str(repo_id),
+ sha256 = sha256
+ )
+
+ cursor.execute(
+ '''
+ UPDATE
+ files
+ SET
+ data = ?
+ WHERE
+ file_id = ?;
+ ''',
+ (response.content, file_id)
+ )
+
+def _recompute_dependencies_no_state_update(
+ cursor: sqlite3.Cursor,
+ extra_requirements: t.Iterable[sds.MappingRequirement]
+) -> None:
+ _recompute_dependencies_no_state_update_no_pull_files(
+ cursor,
+ extra_requirements
+ )
+ _pull_missing_files(cursor)