From 367ea85057368047a50ae98a3510e0113eadd744 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 25 Aug 2022 16:37:53 +0200 Subject: [proxy] make it possible to uninstall a package This commit also brings some more refactoring under state_impl/. --- src/hydrilla/proxy/state_impl/base.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'src/hydrilla/proxy/state_impl/base.py') diff --git a/src/hydrilla/proxy/state_impl/base.py b/src/hydrilla/proxy/state_impl/base.py index a889e71..e5a9898 100644 --- a/src/hydrilla/proxy/state_impl/base.py +++ b/src/hydrilla/proxy/state_impl/base.py @@ -49,6 +49,25 @@ from .. import state as st from .. import policies +@contextmanager +def temporary_ids_table( + cursor: sqlite3.Cursor, + ids: t.Iterable[int], + table_name: str = '__helper_ids' +) -> t.Iterator[None]: + cursor.execute( + f'CREATE TEMPORARY TABLE "{table_name}"(id INTEGER PRIMARY KEY);' + ) + + try: + for id in ids: + cursor.execute(f'INSERT INTO "{table_name}" VALUES(?);', (id,)) + + yield + finally: + cursor.execute(f'DROP TABLE "{table_name}";') + + @dc.dataclass(frozen=True) class PolicyTree(pattern_tree.PatternTree[policies.PolicyFactory]): SelfType = t.TypeVar('SelfType', bound='PolicyTree') @@ -105,6 +124,7 @@ def mark_failed_file_installs( (file_sha256, repo_id) ) +NoLockArg = t.Union[t.Sequence[int], t.Literal['all_mappings_unlocked']] PayloadsData = t.Mapping[st.PayloadRef, st.PayloadData] @@ -199,13 +219,15 @@ class HaketiloStateWithFields(st.HaketiloState): def import_items(self, malcontent_path: Path, repo_id: int = 1) -> None: ... + @abstractmethod + def prune_orphans(self) -> None: + ... + @abstractmethod def recompute_dependencies( self, - requirements: t.Iterable[sds.MappingRequirement] = [], - prune_orphans: bool = False + unlocked_required_mappings: NoLockArg = [] ) -> None: - """....""" ... @abstractmethod -- cgit v1.2.3