From 43ff8d070c3363f4aa7546d6639e20568f503fff Mon Sep 17 00:00:00 2001
From: Vinicius Moreira
Date: Wed, 29 Apr 2020 14:46:26 -0300
Subject: [PATCH] [improvement][trim] the dialog is now displayed before the
upgrading process
---
CHANGELOG.md | 2 +
bauh/view/qt/colors.py | 1 +
bauh/view/qt/history.py | 5 ++-
bauh/view/qt/thread.py | 79 ++++++++++++++++-------------------
bauh/view/resources/locale/ca | 2 +-
bauh/view/resources/locale/de | 2 +-
bauh/view/resources/locale/en | 2 +-
bauh/view/resources/locale/es | 2 +-
bauh/view/resources/locale/it | 2 +-
bauh/view/resources/locale/pt | 2 +-
bauh/view/resources/locale/ru | 2 +-
bauh/view/resources/locale/tr | 2 +-
12 files changed, 51 insertions(+), 52 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 72c69645..e16043a4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Improvements
- Backup
- new **type** field on settings to specify the Timeshift backup mode: **RSYNC** or **BTRFS**
+- Trim
+ - the dialog is now displayed before the upgrading process (but the operation is only executed after a successful upgrade)
### UI
- icons, buttons and colors changes
diff --git a/bauh/view/qt/colors.py b/bauh/view/qt/colors.py
index c73a6068..d6c65ac1 100644
--- a/bauh/view/qt/colors.py
+++ b/bauh/view/qt/colors.py
@@ -1 +1,2 @@
GREEN = '#91a069'
+ORANGE = '#ECB03E'
diff --git a/bauh/view/qt/history.py b/bauh/view/qt/history.py
index aebd4cf6..1a1855bf 100644
--- a/bauh/view/qt/history.py
+++ b/bauh/view/qt/history.py
@@ -7,7 +7,8 @@ from PyQt5.QtWidgets import QDialog, QVBoxLayout, QTableWidget, QTableWidgetItem
from bauh.api.abstract.cache import MemoryCache
from bauh.api.abstract.model import PackageHistory
-from bauh.view.qt.view_model import get_type_label, PackageView
+from bauh.view.qt.colors import GREEN, ORANGE
+from bauh.view.qt.view_model import PackageView
from bauh.view.util.translation import I18n
@@ -43,7 +44,7 @@ class HistoryDialog(QDialog):
item.setText(str(data[key]))
if current_status:
- item.setBackground(QColor('#ffbf00' if row != 0 else '#32CD32'))
+ item.setBackground(QColor(ORANGE if row != 0 else GREEN))
tip = '{}. {}.'.format(i18n['popup.history.selected.tooltip'], i18n['version.{}'.format('updated'if row == 0 else 'outdated')].capitalize())
item.setToolTip(tip)
diff --git a/bauh/view/qt/thread.py b/bauh/view/qt/thread.py
index b31c0713..b9029afb 100644
--- a/bauh/view/qt/thread.py
+++ b/bauh/view/qt/thread.py
@@ -213,19 +213,6 @@ class UpgradeSelected(AsyncAction):
read_only=True,
icon_path=icon_path)
- def filter_to_update(self) -> Tuple[List[PackageView], bool]: # packages to update and if they require root privileges
- to_update, requires_root = [], False
- root_user = user.is_root()
-
- for pkg in self.pkgs:
- if pkg.model.update and pkg.update_checked:
- to_update.append(pkg)
-
- if not root_user and not requires_root and self.manager.requires_root('update', pkg.model):
- requires_root = True
-
- return to_update, requires_root
-
def _sum_pkgs_size(self, reqs: List[UpgradeRequirement]) -> Tuple[int, int]:
required, extra = 0, 0
for r in reqs:
@@ -284,26 +271,30 @@ class UpgradeSelected(AsyncAction):
return FormComponent(label=lb, components=comps), (required_size, extra_size)
- def _trim_disk(self, root_password: str, ask: bool):
- if not ask or self.request_confirmation(title=self.i18n['confirmation'].capitalize(), body=self.i18n['action.trim_disk.ask']):
-
- pwd = root_password
-
- if not pwd and user.is_root():
- pwd, success = self.request_root_password()
-
- if not success:
- return
-
- self.change_status('{}...'.format(self.i18n['action.disk_trim'].capitalize()))
- self.change_substatus('')
-
- success, output = ProcessHandler(self).handle_simple(SimpleProcess(['fstrim', '/', '-v'], root_password=pwd))
+ def _request_password(self) -> Tuple[bool, str]:
+ if not user.is_root():
+ pwd, success = self.request_root_password()
if not success:
- self.show_message(title=self.i18n['success'].capitalize(),
- body=self.i18n['action.disk_trim.error'],
- type_=MessageType.ERROR)
+ return False, None
+
+ return True, pwd
+
+ return True, None
+
+ def _ask_for_trim(self) -> bool:
+ return self.request_confirmation(title=self.i18n['confirmation'].capitalize(), body=self.i18n['action.trim_disk.ask'])
+
+ def _trim_disk(self, root_password: str):
+ self.change_status('{}...'.format(self.i18n['action.disk_trim'].capitalize()))
+ self.change_substatus('')
+
+ success, output = ProcessHandler(self).handle_simple(SimpleProcess(['fstrim', '/', '-v'], root_password=root_password))
+
+ if not success:
+ self.show_message(title=self.i18n['success'].capitalize(),
+ body=self.i18n['action.disk_trim.error'],
+ type_=MessageType.ERROR)
def _write_summary_log(self, upgrade_id: str, requirements: UpgradeRequirements):
try:
@@ -366,17 +357,14 @@ class UpgradeSelected(AsyncAction):
traceback.print_exc()
def run(self):
- to_update, requires_root = self.filter_to_update()
-
- root_password = None
+ valid_password, root_password = self._request_password()
- if not user.is_root() and requires_root:
- root_password, ok = self.request_root_password()
+ if not valid_password:
+ self.notify_finished({'success': False, 'updated': 0, 'types': set(), 'id': None})
+ self.pkgs = None
+ return
- if not ok:
- self.notify_finished({'success': False, 'updated': 0, 'types': set(), 'id': None})
- self.pkgs = None
- return
+ to_update = [pkg for pkg in self.pkgs if pkg.model.update and pkg.update_checked]
if len(to_update) > 1:
self.disable_progress_controll()
@@ -432,6 +420,13 @@ class UpgradeSelected(AsyncAction):
app_config = read_config()
+ # trim dialog
+ if app_config['disk']['trim']['after_upgrade'] is not False:
+ should_trim = app_config['disk']['trim']['after_upgrade'] or self._ask_for_trim()
+ else:
+ should_trim = False
+
+ # backup process ( if enabled, supported and accepted )
if bool(app_config['backup']['enabled']) and app_config['backup']['upgrade'] in (True, None) and timeshift.is_available():
any_requires_bkp = False
@@ -460,8 +455,8 @@ class UpgradeSelected(AsyncAction):
updated = len(requirements.to_upgrade)
updated_types.update((req.pkg.__class__ for req in requirements.to_upgrade))
- if app_config['disk']['trim']['after_upgrade'] is not False:
- self._trim_disk(root_password, ask=app_config['disk']['trim']['after_upgrade'] is None)
+ if should_trim:
+ self._trim_disk(root_password)
msg = '{}
{}
{}
'.format(self.i18n['action.update.success.reboot.line1'],
self.i18n['action.update.success.reboot.line2'],
diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca
index d650a268..03a1758a 100644
--- a/bauh/view/resources/locale/ca
+++ b/bauh/view/resources/locale/ca
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Some changes may require a system restart to
action.update.success.reboot.line3=Restart now ?
action.update.summary=Upgrade summary
action.update.total_size=Update size
-action.trim_disk.ask=Optimize disc (trim) ?
+action.trim_disk.ask=Optimize disc (trim) after upgrading ?
address=adreça
all_files=tots els fitxers
amount=amount
diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de
index 5b4f48e6..b95c1078 100644
--- a/bauh/view/resources/locale/de
+++ b/bauh/view/resources/locale/de
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Some changes may require a system restart to
action.update.success.reboot.line3=Restart now ?
action.update.summary=Upgrade summary
action.update.total_size=Update size
-action.trim_disk.ask=Optimize disc (trim) ?
+action.trim_disk.ask=Optimize disc (trim) after upgrading ?
address=Adresse
all_files=Alle Dateien
amount=amount
diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en
index 1216adb5..b594ccf3 100644
--- a/bauh/view/resources/locale/en
+++ b/bauh/view/resources/locale/en
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Some changes may require a system restart to
action.update.success.reboot.line3=Restart now ?
action.update.summary=Upgrade summary
action.update.total_size=Update size
-action.trim_disk.ask=Optimize disc (trim) ?
+action.trim_disk.ask=Optimize disc (trim) after upgrading ?
address=address
all_files=all files
amount=amount
diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es
index 7800149d..0fa23bd8 100644
--- a/bauh/view/resources/locale/es
+++ b/bauh/view/resources/locale/es
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Algunos cambios pueden requerir un reinicio d
action.update.success.reboot.line3=¿Reiniciar ahora?
action.update.summary=Resumen de actualización
action.update.total_size=Tamaño de la actualización
-action.trim_disk.ask=¿Optimizar el disco (trim)?
+action.trim_disk.ask=¿Optimizar el disco (trim) después de actualizar?
address=dirección
all_files=todos los archivos
amount=cantidad
diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it
index 0f4c86fc..169854d7 100644
--- a/bauh/view/resources/locale/it
+++ b/bauh/view/resources/locale/it
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Some changes may require a system restart to
action.update.success.reboot.line3=Restart now ?
action.update.summary=Upgrade summary
action.update.total_size=Update size
-action.trim_disk.ask=Optimize disc (trim) ?
+action.trim_disk.ask=Optimize disc (trim) after upgrading ?
address=indirizzo
all_files=tutti i files
amount=amount
diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt
index 17023f2f..a1e763b0 100644
--- a/bauh/view/resources/locale/pt
+++ b/bauh/view/resources/locale/pt
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Algumas alterações podem exigir a reinicial
action.update.success.reboot.line3=Reiniciar agora ?
action.update.summary=Resumo de atualização
action.update.total_size=Tamanho da atualização
-action.trim_disk.ask=Otimizar disco (trim) ?
+action.trim_disk.ask=Otimizar disco (trim) depois de atualizar ?
address=endereço
all_files=todos os arquivos
amount=quantidade
diff --git a/bauh/view/resources/locale/ru b/bauh/view/resources/locale/ru
index cfbe6331..bbc5bc8e 100644
--- a/bauh/view/resources/locale/ru
+++ b/bauh/view/resources/locale/ru
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Some changes may require a system restart to
action.update.success.reboot.line3=Restart now ?
action.update.summary=Сводка обновления
action.update.total_size=Update size
-action.trim_disk.ask=Optimize disc (trim) ?
+action.trim_disk.ask=Optimize disc (trim) after upgrading ?
address=Адрес
all_files=Все файлы
amount=amount
diff --git a/bauh/view/resources/locale/tr b/bauh/view/resources/locale/tr
index 9470b884..5a0d7d98 100644
--- a/bauh/view/resources/locale/tr
+++ b/bauh/view/resources/locale/tr
@@ -80,7 +80,7 @@ action.update.success.reboot.line2=Bazı değişiklikler, sistemin etkinleşmesi
action.update.success.reboot.line3=Şimdi yeniden başlat ?
action.update.summary=Yükseltme özeti
action.update.total_size=Güncelleme boyutu
-action.trim_disk.ask=Diski optimize edin (trim) ?
+action.trim_disk.ask=Diski optimize edin (trim) after upgrading ?
address=adres
all_files=tüm dosyalar
amount=miktar