From d516b9decad07b940b3cd117fc4e353dd8bbe7d2 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Wed, 24 Aug 2022 10:47:33 +0200 Subject: make repo packages (mappings) load as uninstalled; make them installable through the web UI --- .../_operations/recompute_dependencies.py | 64 ++++------------------ 1 file changed, 12 insertions(+), 52 deletions(-) (limited to 'src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py') diff --git a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py index 2b18a51..494d130 100644 --- a/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py +++ b/src/hydrilla/proxy/state_impl/_operations/recompute_dependencies.py @@ -34,13 +34,10 @@ from __future__ import annotations import sqlite3 import typing as t -from urllib.parse import urlparse, urljoin - -import requests - from .... import item_infos from ... import simple_dependency_satisfying as sds -from ... import state +from .pull_missing_files import pull_missing_files, FileResolver, \ + DummyFileResolver AnyInfoVar = t.TypeVar( @@ -165,7 +162,8 @@ def _recompute_dependencies_no_state_update_no_pull_files( for choice in mapping_choices.values(): mapping_ver_id = mappings_to_ids[choice.info.identifier] - _mark_version_installed(cursor, mapping_ver_id) + if choice.required: + _mark_version_installed(cursor, mapping_ver_id) cursor.execute( ''' @@ -200,7 +198,7 @@ def _recompute_dependencies_no_state_update_no_pull_files( INSERT INTO payloads( mapping_item_id, pattern, - eval_allowed, + eval_allowed, cors_bypass_allowed ) VALUES (?, ?, ?, ?); @@ -230,7 +228,8 @@ def _recompute_dependencies_no_state_update_no_pull_files( 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) + if choice.required: + _mark_version_installed(cursor, resource_ver_id) cursor.execute( ''' @@ -244,53 +243,14 @@ def _recompute_dependencies_no_state_update_no_pull_files( (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, sha256, 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] + cursor: sqlite3.Cursor, + extra_requirements: t.Iterable[sds.MappingRequirement] = (), + semirepo_file_resolver: FileResolver = DummyFileResolver() ) -> None: _recompute_dependencies_no_state_update_no_pull_files( cursor, extra_requirements ) - _pull_missing_files(cursor) + + pull_missing_files(cursor, semirepo_file_resolver) -- cgit v1.2.3