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.py82
1 files changed, 46 insertions, 36 deletions
diff --git a/src/hydrilla/proxy/state_impl/mappings.py b/src/hydrilla/proxy/state_impl/mappings.py
index 8a401b8..eb8b4d2 100644
--- a/src/hydrilla/proxy/state_impl/mappings.py
+++ b/src/hydrilla/proxy/state_impl/mappings.py
@@ -183,11 +183,8 @@ class ConcreteMappingStore(st.MappingStore):
class ConcreteMappingVersionRef(st.MappingVersionRef):
state: base.HaketiloStateWithFields = dc.field(hash=False, compare=False)
- def _set_installed_status(
- self,
- cursor: sqlite3.Cursor,
- new_status: st.InstalledStatus
- ) -> None:
+ def _set_installed_status(self, cursor: sqlite3.Cursor, new_status: str) \
+ -> None:
cursor.execute(
'''
UPDATE
@@ -197,50 +194,63 @@ class ConcreteMappingVersionRef(st.MappingVersionRef):
WHERE
item_version_id = ?;
''',
- (new_status.value, self.id,)
+ (new_status, self.id,)
)
- def install(self) -> None:
- with self.state.cursor(transaction=True) as cursor:
- cursor.execute(
- '''
- SELECT
- installed
- FROM
- item_versions
- WHERE
- item_version_id = ?;
- ''',
- (self.id,)
- )
+ def _get_statuses(self, cursor: sqlite3.Cursor) -> t.Tuple[str, str]:
+ cursor.execute(
+ '''
+ SELECT
+ installed, active
+ FROM
+ item_versions
+ WHERE
+ item_version_id = ?;
+ ''',
+ (self.id,)
+ )
- rows = cursor.fetchall()
+ rows = cursor.fetchall()
- if rows == []:
- raise st.MissingItemError()
+ if rows == []:
+ raise st.MissingItemError()
+
+ (installed_status, active_status), = rows
- (installed_status,), = rows
+ return installed_status, active_status
+
+ def install(self) -> None:
+ with self.state.cursor(transaction=True) as cursor:
+ installed_status, _ = self._get_statuses(cursor)
if installed_status == 'I':
return
- self._set_installed_status(cursor, st.InstalledStatus.INSTALLED)
+ self._set_installed_status(cursor, 'I')
self.state.pull_missing_files()
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
- #
- # ....
+ with self.state.cursor(transaction=True) as cursor:
+ installed_status, active_status = self._get_statuses(cursor)
+
+ if installed_status == 'N':
+ return
+
+ self._set_installed_status(cursor, 'N')
+
+ self.state.prune_orphans()
+
+ if active_status == 'R':
+ self.state.recompute_dependencies()
+
+ cursor.execute(
+ 'SELECT COUNT(*) FROM item_versions WHERE item_version_id = ?;',
+ (self.id,)
+ )
+
+ (version_still_present,), = cursor.fetchall()
+ return self if version_still_present else None
def get_all_version_display_infos(self) \
-> t.Sequence[st.MappingVersionDisplayInfo]: