mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 05:54:15 +02:00
[improvement][trim] the dialog is now displayed before the upgrading process
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
GREEN = '#91a069'
|
||||
ORANGE = '#ECB03E'
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 = '<p>{}</p>{}</p><br/><p>{}</p>'.format(self.i18n['action.update.success.reboot.line1'],
|
||||
self.i18n['action.update.success.reboot.line2'],
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user