mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 01:14:15 +02:00
[feature] new 'restore' custom action
This commit is contained in:
@@ -4,7 +4,10 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## [0.9.3] 2020
|
||||
## [0.9.3] 2020-05
|
||||
### Features
|
||||
- new **restore** action to restore bauh settings and cache through the 'custom actions' button (**+**). It is equivalent to the command `bauh --reset`.
|
||||
|
||||
### Fixes
|
||||
- Arch
|
||||
- 'clean cache' operation was not working in some scenarios
|
||||
|
||||
@@ -312,7 +312,7 @@ class SoftwareManager(ABC):
|
||||
"""
|
||||
pass
|
||||
|
||||
def clear_data(self):
|
||||
def clear_data(self, logs: bool = True):
|
||||
"""
|
||||
Removes all data created by the SoftwareManager instance
|
||||
"""
|
||||
|
||||
@@ -7,7 +7,7 @@ from bauh.api.constants import CACHE_PATH
|
||||
|
||||
class CustomSoftwareAction:
|
||||
|
||||
def __init__(self, i18_label_key: str, i18n_status_key: str, icon_path: str, manager_method: str, requires_root: bool, manager: "SoftwareManager" = None, backup: bool = False):
|
||||
def __init__(self, i18_label_key: str, i18n_status_key: str, icon_path: str, manager_method: str, requires_root: bool, manager: "SoftwareManager" = None, backup: bool = False, refresh: bool = True):
|
||||
"""
|
||||
:param i18_label_key: the i18n key that will be used to display the action name
|
||||
:param i18n_status_key: the i18n key that will be used to display the action name being executed
|
||||
@@ -16,6 +16,7 @@ class CustomSoftwareAction:
|
||||
:param manager: the instance that will execute the action ( optional )
|
||||
:param backup: if a system backup should be performed before executing the action
|
||||
:param requires_root:
|
||||
:param refresh: if the a full app refresh should be done if the action succeeds
|
||||
"""
|
||||
self.i18_label_key = i18_label_key
|
||||
self.i18n_status_key = i18n_status_key
|
||||
@@ -24,6 +25,7 @@ class CustomSoftwareAction:
|
||||
self.requires_root = requires_root
|
||||
self.manager = manager
|
||||
self.backup = backup
|
||||
self.refresh = refresh
|
||||
|
||||
def __hash__(self):
|
||||
return self.i18_label_key.__hash__() + self.i18n_status_key.__hash__() + self.manager_method.__hash__()
|
||||
|
||||
@@ -613,15 +613,19 @@ class AppImageManager(SoftwareManager):
|
||||
|
||||
return []
|
||||
|
||||
def clear_data(self):
|
||||
def clear_data(self, logs: bool = True):
|
||||
for f in glob.glob('{}/*.db'.format(LOCAL_PATH)):
|
||||
try:
|
||||
print('[bauh][appimage] Deleting {}'.format(f))
|
||||
if logs:
|
||||
print('[bauh][appimage] Deleting {}'.format(f))
|
||||
os.remove(f)
|
||||
print('{}[bauh][appimage] {} deleted{}'.format(Fore.YELLOW, f, Fore.RESET))
|
||||
|
||||
if logs:
|
||||
print('{}[bauh][appimage] {} deleted{}'.format(Fore.YELLOW, f, Fore.RESET))
|
||||
except:
|
||||
print('{}[bauh][appimage] An exception has happened when deleting {}{}'.format(Fore.RED, f, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
if logs:
|
||||
print('{}[bauh][appimage] An exception has happened when deleting {}{}'.format(Fore.RED, f, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
config = read_config()
|
||||
|
||||
@@ -944,16 +944,19 @@ class WebApplicationManager(SoftwareManager):
|
||||
def get_screenshots(self, pkg: SoftwarePackage) -> List[str]:
|
||||
pass
|
||||
|
||||
def clear_data(self):
|
||||
def clear_data(self, logs: bool = True):
|
||||
if os.path.exists(ENV_PATH):
|
||||
print('[bauh][web] Deleting directory {}'.format(ENV_PATH))
|
||||
if logs:
|
||||
print('[bauh][web] Deleting directory {}'.format(ENV_PATH))
|
||||
|
||||
try:
|
||||
shutil.rmtree(ENV_PATH)
|
||||
print('{}[bauh][web] Directory {} deleted{}'.format(Fore.YELLOW, ENV_PATH, Fore.RESET))
|
||||
if logs:
|
||||
print('{}[bauh][web] Directory {} deleted{}'.format(Fore.YELLOW, ENV_PATH, Fore.RESET))
|
||||
except:
|
||||
print('{}[bauh][web] An exception has happened when deleting {}{}'.format(Fore.RED, ENV_PATH, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
if logs:
|
||||
print('{}[bauh][web] An exception has happened when deleting {}{}'.format(Fore.RED, ENV_PATH, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
|
||||
def get_settings(self, screen_width: int, screen_height: int) -> ViewComponent:
|
||||
config = read_config()
|
||||
|
||||
@@ -14,8 +14,11 @@ from bauh.api.abstract.model import SoftwarePackage, PackageUpdate, PackageHisto
|
||||
from bauh.api.abstract.view import ViewComponent, TabGroupComponent
|
||||
from bauh.api.exception import NoInternetException
|
||||
from bauh.commons import internet
|
||||
from bauh.commons.html import bold
|
||||
from bauh.view.core.settings import GenericSettingsManager
|
||||
from bauh.view.core.update import check_for_update
|
||||
from bauh.view.util import resource
|
||||
from bauh.view.util.util import clean_app_files, restart_app
|
||||
|
||||
RE_IS_URL = re.compile(r'^https?://.+')
|
||||
|
||||
@@ -47,6 +50,13 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
self.config = config
|
||||
self.settings_manager = settings_manager
|
||||
self.http_client = context.http_client
|
||||
self.extra_actions = [CustomSoftwareAction(i18_label_key='action.reset',
|
||||
i18n_status_key='action.reset.status',
|
||||
manager_method='reset',
|
||||
manager=self,
|
||||
icon_path=resource.get_path('img/logo.svg'),
|
||||
requires_root=False,
|
||||
refresh=False)]
|
||||
|
||||
def reset_cache(self):
|
||||
if self._available_cache is not None:
|
||||
@@ -473,10 +483,25 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
|
||||
return res
|
||||
|
||||
def get_custom_actions(self) -> List[CustomSoftwareAction]:
|
||||
if self.managers:
|
||||
actions = []
|
||||
def reset(self, root_password: str, watcher: ProcessWatcher) -> bool:
|
||||
body = '<p>{}</p><p>{}</p>'.format(self.i18n['action.reset.body_1'].format(bold(self.context.app_name)),
|
||||
self.i18n['action.reset.body_2'])
|
||||
if watcher.request_confirmation(title=self.i18n['action.reset'],
|
||||
body=body,
|
||||
confirmation_label=self.i18n['proceed'].capitalize(),
|
||||
deny_label=self.i18n['cancel'].capitalize()):
|
||||
|
||||
try:
|
||||
clean_app_files(managers=self.managers, logs=False)
|
||||
restart_app()
|
||||
except:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def get_custom_actions(self) -> List[CustomSoftwareAction]:
|
||||
actions = []
|
||||
if self.managers:
|
||||
working_managers = []
|
||||
|
||||
for man in self.managers:
|
||||
@@ -492,7 +517,8 @@ class GenericSoftwareManager(SoftwareManager):
|
||||
if man_actions:
|
||||
actions.extend(man_actions)
|
||||
|
||||
return actions
|
||||
actions.extend(self.extra_actions)
|
||||
return actions
|
||||
|
||||
def _fill_sizes(self, man: SoftwareManager, pkgs: List[SoftwarePackage]):
|
||||
ti = time.time()
|
||||
|
||||
@@ -874,7 +874,7 @@ class CustomAction(AsyncAction):
|
||||
if self.custom_action.backup:
|
||||
app_config = read_config()
|
||||
if not self.request_backup(app_config, None, self.i18n, self.root_pwd):
|
||||
self.notify_finished({'success': False, 'pkg': self.pkg})
|
||||
self.notify_finished({'success': False, 'pkg': self.pkg, 'action': self.custom_action})
|
||||
self.pkg = None
|
||||
self.custom_action = None
|
||||
self.root_pwd = None
|
||||
@@ -889,7 +889,7 @@ class CustomAction(AsyncAction):
|
||||
success = False
|
||||
self.signal_output.emit(self.i18n['internet.required'])
|
||||
|
||||
self.notify_finished({'success': success, 'pkg': self.pkg})
|
||||
self.notify_finished({'success': success, 'pkg': self.pkg, 'action': self.custom_action})
|
||||
self.pkg = None
|
||||
self.custom_action = None
|
||||
self.root_pwd = None
|
||||
|
||||
@@ -1226,7 +1226,8 @@ class ManageWindow(QWidget):
|
||||
def _finish_custom_action(self, res: dict):
|
||||
self.finish_action()
|
||||
if res['success']:
|
||||
self.refresh_packages(pkg_types={res['pkg'].model.__class__} if res['pkg'] else None)
|
||||
if res['action'].refresh:
|
||||
self.refresh_packages(pkg_types={res['pkg'].model.__class__} if res['pkg'] else None)
|
||||
else:
|
||||
self.checkbox_console.setChecked(True)
|
||||
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=No history
|
||||
action.info.tooltip=Feu clic aquí per a veure informació sobre aquesta aplicació
|
||||
action.not_allowed=Action not allowed
|
||||
action.request_reboot.title=System restart
|
||||
action.reset=Restore
|
||||
action.reset.status=Restoring
|
||||
action.reset.body_1=This operation will restore {} default settings and clean its cache.
|
||||
action.reset.body_2=It will be restarted after the operation is finished.
|
||||
action.run.tooltip=Feu clic aquí per a iniciar l’aplicació
|
||||
action.screenshots.tooltip=Feu clic aquí per a veure imatges d’aquesta aplicació
|
||||
action.settings.tooltip=Feu clic aquí per a obrir accions addicionals
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=No history
|
||||
action.info.tooltip=Informationen über diese Anwendung anzeigen
|
||||
action.not_allowed=Action not allowed
|
||||
action.request_reboot.title=System restart
|
||||
action.reset=Restore
|
||||
action.reset.status=Restoring
|
||||
action.reset.body_1=This operation will restore {} default settings and clean its cache.
|
||||
action.reset.body_2=It will be restarted after the operation is finished.
|
||||
action.run.tooltip=Die Anwendung ausführen
|
||||
action.screenshots.tooltip=Fotos der Anwendung anzeigen
|
||||
action.settings.tooltip=Weitere Optionen anzeigen
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=No history
|
||||
action.info.tooltip=Click here to see information about this application
|
||||
action.not_allowed=Action not allowed
|
||||
action.request_reboot.title=System restart
|
||||
action.reset=Restore
|
||||
action.reset.status=Restoring
|
||||
action.reset.body_1=This operation will restore {} default settings and clean its cache.
|
||||
action.reset.body_2=It will be restarted after the operation is finished.
|
||||
action.run.tooltip=Click here to launch this application
|
||||
action.screenshots.tooltip=Click here to see some pictures of this application
|
||||
action.settings.tooltip=Click here to open extra actions
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=No history
|
||||
action.info.tooltip=Pulse aquí para ver información sobre esta aplicación
|
||||
action.not_allowed=Acción no permitida
|
||||
action.request_reboot.title=Reinicio de sistema
|
||||
action.reset=Restaurar
|
||||
action.reset.status=Restaurando
|
||||
action.reset.body_1=Esta operación restaurará las configuraciónes de {} y limpiará su caché.
|
||||
action.reset.body_2=Él será reiniciado una vez que la operación esté terminada.
|
||||
action.run.tooltip=Pulse aquí para iniciar la aplicación
|
||||
action.screenshots.tooltip=Pulse aquí para ver algunas fotos de esta aplicación
|
||||
action.settings.tooltip=Pulse aquí para abrir acciones adicionales
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=No history
|
||||
action.info.tooltip=Clicca qui per vedere informazioni su questa applicazione
|
||||
action.not_allowed=Action not allowed
|
||||
action.request_reboot.title=System restart
|
||||
action.reset=Restore
|
||||
action.reset.status=Restoring
|
||||
action.reset.body_1=This operation will restore {} default settings and clean its cache.
|
||||
action.reset.body_2=It will be restarted after the operation is finished.
|
||||
action.run.tooltip=Fai clic qui per avviare questa applicazione
|
||||
action.screenshots.tooltip=Clicca qui per vedere alcune immagini di questa applicazione
|
||||
action.settings.tooltip=Fai clic qui per aprire ulteriori azioni
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=Sem histórico
|
||||
action.info.tooltip=Clique aqui para ver informações sobre este aplicativo
|
||||
action.not_allowed=Ação não permitida
|
||||
action.request_reboot.title=Reinicialização de sistema
|
||||
action.reset=Restaurar
|
||||
action.reset.status=Restaurando
|
||||
action.reset.body_1=Essa operação restaurará as configurações padrões e limpará o cache do {}.
|
||||
action.reset.body_2=Ele será reinicializado após a operação ser concluída.
|
||||
action.run.tooltip=Clique aqui para iniciar esse aplicativo
|
||||
action.screenshots.tooltip=Clique aqui para ver algumas fotos desse aplicativo
|
||||
action.settings.tooltip=Clique aqui para abrir ações adicionais
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=No history
|
||||
action.info.tooltip=Нажмите здесь, чтобы посмотреть информацию об этом приложении
|
||||
action.not_allowed=Действие не допускается
|
||||
action.request_reboot.title=System restart
|
||||
action.reset=Restore
|
||||
action.reset.status=Restoring
|
||||
action.reset.body_1=This operation will restore {} default settings and clean its cache.
|
||||
action.reset.body_2=It will be restarted after the operation is finished.
|
||||
action.run.tooltip=Нажмите здесь, чтобы запустить это приложение
|
||||
action.screenshots.tooltip=Нажмите здесь, чтобы увидеть некоторые скриншоты этого приложения
|
||||
action.settings.tooltip=Нажмите здесь, чтобы открыть дополнительные действия
|
||||
|
||||
@@ -60,6 +60,10 @@ action.history.no_history.title=Geçmiş yok
|
||||
action.info.tooltip=Uygulama bilgilerini görmek için buraya tıkla
|
||||
action.not_allowed=Eyleme izin verilmiyor
|
||||
action.request_reboot.title=Sistemi yeniden başlat
|
||||
action.reset=Restore
|
||||
action.reset.status=Restoring
|
||||
action.reset.body_1=This operation will restore {} default settings and clean its cache.
|
||||
action.reset.body_2=It will be restarted after the operation is finished.
|
||||
action.run.tooltip=Uygulamayı başlatmak için burayı tıkla
|
||||
action.screenshots.tooltip=Bu uygulamanın bazı resimlerini görmek için buraya tıklayın
|
||||
action.settings.tooltip=Extra eylemleri açmak için buraya tıkla
|
||||
|
||||
@@ -56,20 +56,28 @@ def get_distro():
|
||||
return 'unknown'
|
||||
|
||||
|
||||
def clean_app_files(managers: List[SoftwareManager]):
|
||||
print('[bauh] Cleaning configuration and cache files')
|
||||
def clean_app_files(managers: List[SoftwareManager], logs: bool = True):
|
||||
|
||||
if logs:
|
||||
print('[bauh] Cleaning configuration and cache files')
|
||||
|
||||
for path in (CACHE_PATH, CONFIG_PATH):
|
||||
print('[bauh] Deleting directory {}'.format(path))
|
||||
if logs:
|
||||
print('[bauh] Deleting directory {}'.format(path))
|
||||
|
||||
if os.path.exists(path):
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
print('{}[bauh] Directory {} deleted{}'.format(Fore.YELLOW, path, Fore.RESET))
|
||||
if logs:
|
||||
print('{}[bauh] Directory {} deleted{}'.format(Fore.YELLOW, path, Fore.RESET))
|
||||
except:
|
||||
print('{}[bauh] An exception has happened when deleting {}{}'.format(Fore.RED, path, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
if logs:
|
||||
print('{}[bauh] An exception has happened when deleting {}{}'.format(Fore.RED, path, Fore.RESET))
|
||||
traceback.print_exc()
|
||||
|
||||
if managers:
|
||||
for m in managers:
|
||||
m.clear_data()
|
||||
|
||||
print('[bauh] Cleaning finished')
|
||||
if logs:
|
||||
print('[bauh] Cleaning finished')
|
||||
|
||||
Reference in New Issue
Block a user