[arch] refactoring: removal confirmation methods

This commit is contained in:
Vinicius Moreira
2022-04-07 11:39:06 -03:00
parent 1035e32986
commit 81c6e9d607

View File

@@ -1225,14 +1225,15 @@ class ArchManager(SoftwareManager):
return all_uninstalled return all_uninstalled
def _request_uninstall_confirmation(self, to_uninstall: Collection[str], required: Collection[str], def _confirm_removal(self, to_remove: Collection[str], required: Collection[str],
data: Optional[Dict[str, Dict[str, str]]], watcher: ProcessWatcher) -> bool: watcher: ProcessWatcher, data: Optional[Dict[str, Dict[str, str]]] = None) -> bool:
reqs = self._map_as_input_options(required, data, read_only=True) required_data = data if data is not None else self._map_installed_data_for_removal(required)
reqs = self._map_as_input_options(required, required_data, read_only=True)
reqs_select = MultipleSelectComponent(options=reqs, default_options=set(reqs), label="") reqs_select = MultipleSelectComponent(options=reqs, default_options=set(reqs), label="")
main_msg = self.i18n['arch.uninstall.required_by'].format(no=bold(str(len(required))), main_msg = self.i18n['arch.uninstall.required_by'].format(no=bold(str(len(required))),
pkgs=', '.join(bold(n)for n in to_uninstall)) + '.' pkgs=', '.join(bold(n) for n in to_remove)) + '.'
full_msg = f"<p>{main_msg}</p><p>{self.i18n['arch.uninstall.required_by.warn'] + '.'}</p>" full_msg = f"<p>{main_msg}</p><p>{self.i18n['arch.uninstall.required_by.warn'] + '.'}</p>"
@@ -1264,8 +1265,10 @@ class ArchManager(SoftwareManager):
return opts return opts
def _request_unncessary_uninstall_confirmation(self, unnecessary: Iterable[str], data: Optional[Dict[str, Dict[str, str]]], watcher: ProcessWatcher) -> Optional[Set[str]]: def _confirm_unneeded_removal(self, unnecessary: Iterable[str], watcher: ProcessWatcher,
reqs = self._map_as_input_options(unnecessary, data) data: Optional[Dict[str, Dict[str, str]]] = None) -> Optional[Set[str]]:
unneeded_data = data if data is not None else self._map_installed_data_for_removal(unnecessary)
reqs = self._map_as_input_options(unnecessary, unneeded_data)
reqs_select = MultipleSelectComponent(options=reqs, default_options=set(reqs), label="") reqs_select = MultipleSelectComponent(options=reqs, default_options=set(reqs), label="")
if not watcher.request_confirmation(title=self.i18n['arch.uninstall.unnecessary.l1'], if not watcher.request_confirmation(title=self.i18n['arch.uninstall.unnecessary.l1'],
@@ -1281,7 +1284,7 @@ class ArchManager(SoftwareManager):
data: Optional[Dict[str, Dict[str, str]]] = None) -> bool: data: Optional[Dict[str, Dict[str, str]]] = None) -> bool:
unnecessary_data = data if data is not None else self._map_installed_data_for_removal(pkgs) unnecessary_data = data if data is not None else self._map_installed_data_for_removal(pkgs)
reqs = self._map_as_input_options(pkgs, unnecessary_data, read_only=True) reqs = self._map_as_input_options(pkgs, unnecessary_data, read_only=True)
reqs_select = MultipleSelectComponent(options=reqs, default_options=set(reqs), label="", max_per_line=1) reqs_select = MultipleSelectComponent(options=reqs, default_options=set(reqs), label="")
if not context.watcher.request_confirmation(title=self.i18n['confirmation'].capitalize(), if not context.watcher.request_confirmation(title=self.i18n['confirmation'].capitalize(),
body=self.i18n['arch.uninstall.unnecessary.all'].format(bold(str(len(pkgs)))), body=self.i18n['arch.uninstall.unnecessary.all'].format(bold(str(len(pkgs)))),
@@ -1322,12 +1325,8 @@ class ArchManager(SoftwareManager):
if hard_requirements: if hard_requirements:
to_uninstall.update(hard_requirements) to_uninstall.update(hard_requirements)
hard_reqs_data = self._map_installed_data_for_removal(hard_requirements)
if not self._request_uninstall_confirmation(to_uninstall=names, if not self._confirm_removal(to_remove=names, required=hard_requirements, watcher=context.watcher):
required=hard_requirements,
data=hard_reqs_data,
watcher=context.watcher):
return False return False
if not skip_requirements and remove_unneeded: if not skip_requirements and remove_unneeded:
@@ -1368,10 +1367,8 @@ class ArchManager(SoftwareManager):
self._update_progress(context, 70) self._update_progress(context, 70)
if unnecessary_packages: if unnecessary_packages:
unnecessary_data = self._map_installed_data_for_removal(unnecessary_packages) unnecessary_to_uninstall = self._confirm_unneeded_removal(unnecessary=unnecessary_packages,
unnecessary_to_uninstall = self._request_unncessary_uninstall_confirmation(unnecessary=unnecessary_packages, watcher=context.watcher)
data=unnecessary_data,
watcher=context.watcher)
if unnecessary_to_uninstall: if unnecessary_to_uninstall:
context.watcher.change_substatus(self.i18n['arch.checking_unnecessary_deps']) context.watcher.change_substatus(self.i18n['arch.checking_unnecessary_deps'])