mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 04:44:15 +02:00
refactoring and fixes
This commit is contained in:
@@ -106,7 +106,7 @@ class GenericApplicationManager(ApplicationManager):
|
||||
def downgrade_app(self, app: Application, root_password: str) -> FpakmanProcess:
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man and man.can_downgrade():
|
||||
if man and app.can_be_downgraded():
|
||||
return man.downgrade_app(app, root_password)
|
||||
else:
|
||||
raise Exception("downgrade is not possible for {}".format(app.__class__.__name__))
|
||||
@@ -117,23 +117,23 @@ class GenericApplicationManager(ApplicationManager):
|
||||
if man:
|
||||
return man.clean_cache_for(app)
|
||||
|
||||
def update_and_stream(self, app: Application) -> FpakmanProcess:
|
||||
def update(self, app: Application, root_password: str) -> FpakmanProcess:
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man:
|
||||
return man.update_and_stream(app)
|
||||
return man.update(app, root_password)
|
||||
|
||||
def uninstall_and_stream(self, app: Application, root_password: str) -> FpakmanProcess:
|
||||
def uninstall(self, app: Application, root_password: str) -> FpakmanProcess:
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man:
|
||||
return man.uninstall_and_stream(app, root_password)
|
||||
return man.uninstall(app, root_password)
|
||||
|
||||
def install_and_stream(self, app: Application, root_password: str) -> FpakmanProcess:
|
||||
def install(self, app: Application, root_password: str) -> FpakmanProcess:
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
if man:
|
||||
return man.install_and_stream(app, root_password)
|
||||
return man.install(app, root_password)
|
||||
|
||||
def get_info(self, app: Application):
|
||||
man = self._get_manager_for(app)
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
import locale
|
||||
|
||||
from fpakman_api.util import system
|
||||
from fpakman_api.util.resource import get_fpakman_logo_path
|
||||
|
||||
from fpakman import ROOT_DIR, __app_name__
|
||||
from fpakman.core import resource
|
||||
import glob
|
||||
import re
|
||||
@@ -43,3 +47,7 @@ def get_locale_keys(key: str = None, locale_dir: str = resource.get_path('locale
|
||||
|
||||
def strip_html(string: str):
|
||||
return HTML_RE.sub('', string)
|
||||
|
||||
|
||||
def notify_user(msg: str, icon_path: str = get_fpakman_logo_path(ROOT_DIR)):
|
||||
system.notify_user(msg=msg, app_name=__app_name__, icon_path=icon_path)
|
||||
|
||||
@@ -6,8 +6,10 @@ from PyQt5.QtCore import QThread, pyqtSignal, QCoreApplication, Qt
|
||||
from PyQt5.QtGui import QIcon
|
||||
from PyQt5.QtWidgets import QSystemTrayIcon, QMenu
|
||||
from fpakman_api.abstract.model import ApplicationUpdate
|
||||
from fpakman_api.util import system
|
||||
from fpakman_api.util.resource import get_fpakman_logo_path
|
||||
|
||||
from fpakman import __app_name__
|
||||
from fpakman import __app_name__, ROOT_DIR
|
||||
from fpakman.core import resource
|
||||
from fpakman.core.controller import ApplicationManager
|
||||
from fpakman.view.qt.about import AboutDialog
|
||||
@@ -99,7 +101,7 @@ class TrayIcon(QSystemTrayIcon):
|
||||
self.setToolTip(msg)
|
||||
|
||||
if self.update_notification and notify_user:
|
||||
system.notify_user(msg)
|
||||
system.notify_user(app_name=__app_name__, msg=msg, icon_path=get_fpakman_logo_path(ROOT_DIR))
|
||||
|
||||
else:
|
||||
self.last_updates.clear()
|
||||
|
||||
@@ -6,10 +6,10 @@ import requests
|
||||
from PyQt5.QtCore import QThread, pyqtSignal
|
||||
from fpakman_api.abstract.model import ApplicationStatus
|
||||
from fpakman_api.exception import NoInternetException
|
||||
from fpakman_api.util.cache import Cache
|
||||
from fpakman_api.util.system import FpakmanProcess
|
||||
|
||||
from fpakman.core.controller import ApplicationManager
|
||||
from fpakman_api.util.cache import Cache
|
||||
from fpakman.view.qt import dialog
|
||||
from fpakman.view.qt.view_model import ApplicationView
|
||||
|
||||
@@ -18,9 +18,8 @@ class AsyncAction(QThread):
|
||||
|
||||
def notify_subproc_outputs(self, proc: FpakmanProcess, signal) -> bool:
|
||||
"""
|
||||
:param subproc:
|
||||
:param signal:
|
||||
:param success:
|
||||
:param proc:
|
||||
:return: if the subprocess succeeded
|
||||
"""
|
||||
signal.emit(' '.join(proc.subproc.args) + '\n')
|
||||
@@ -32,7 +31,7 @@ class AsyncAction(QThread):
|
||||
if line:
|
||||
signal.emit(line)
|
||||
|
||||
if proc.success_pgrase and proc.success_pgrase in line:
|
||||
if proc.success_phrase and proc.success_phrase in line:
|
||||
already_succeeded = True
|
||||
|
||||
if already_succeeded:
|
||||
@@ -60,6 +59,7 @@ class UpdateSelectedApps(AsyncAction):
|
||||
super(UpdateSelectedApps, self).__init__()
|
||||
self.apps_to_update = apps_to_update
|
||||
self.manager = manager
|
||||
self.root_password = None
|
||||
|
||||
def run(self):
|
||||
|
||||
@@ -67,7 +67,7 @@ class UpdateSelectedApps(AsyncAction):
|
||||
|
||||
for app in self.apps_to_update:
|
||||
self.signal_status.emit(app.model.base_data.name)
|
||||
process = self.manager.update_and_stream(app.model)
|
||||
process = self.manager.update(app.model, self.root_password)
|
||||
success = self.notify_subproc_outputs(process, self.signal_output)
|
||||
|
||||
if not success:
|
||||
@@ -104,7 +104,7 @@ class UninstallApp(AsyncAction):
|
||||
|
||||
def run(self):
|
||||
if self.app:
|
||||
process = self.manager.uninstall_and_stream(self.app.model, self.root_password)
|
||||
process = self.manager.uninstall(self.app.model, self.root_password)
|
||||
success = self.notify_subproc_outputs(process, self.signal_output)
|
||||
|
||||
if success:
|
||||
@@ -222,7 +222,7 @@ class InstallApp(AsyncAction):
|
||||
success = False
|
||||
|
||||
try:
|
||||
process = self.manager.install_and_stream(self.app.model, self.root_password)
|
||||
process = self.manager.install(self.app.model, self.root_password)
|
||||
success = self.notify_subproc_outputs(process, self.signal_output)
|
||||
|
||||
if success and self.disk_cache:
|
||||
|
||||
@@ -7,11 +7,11 @@ from PyQt5.QtGui import QIcon, QWindowStateChangeEvent, QPixmap
|
||||
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QApplication, QCheckBox, QHeaderView, QToolButton, QToolBar, \
|
||||
QSizePolicy, QLabel, QPlainTextEdit, QLineEdit, QProgressBar, QHBoxLayout
|
||||
from fpakman_api.abstract.model import Application
|
||||
from fpakman_api.util import system
|
||||
from fpakman_api.util.cache import Cache
|
||||
|
||||
from fpakman.core import resource
|
||||
from fpakman.core.controller import ApplicationManager
|
||||
from fpakman_api.util.cache import Cache
|
||||
from fpakman.util import util
|
||||
from fpakman.view.qt.apps_table import AppsTable
|
||||
from fpakman.view.qt.history import HistoryDialog
|
||||
from fpakman.view.qt.info import InfoDialog
|
||||
@@ -309,13 +309,13 @@ class ManageWindow(QWidget):
|
||||
if success:
|
||||
if self._can_notify_user():
|
||||
app = self.table_apps.get_selected_app()
|
||||
system.notify_user('{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['uninstalled']))
|
||||
util.notify_user('{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['uninstalled']))
|
||||
|
||||
self.refresh_apps()
|
||||
else:
|
||||
if self._can_notify_user():
|
||||
app = self.table_apps.get_selected_app()
|
||||
system.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.uninstall.failed']))
|
||||
util.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.uninstall.failed']))
|
||||
|
||||
self.checkbox_console.setChecked(True)
|
||||
|
||||
@@ -328,7 +328,7 @@ class ManageWindow(QWidget):
|
||||
if success:
|
||||
if self._can_notify_user():
|
||||
app = self.table_apps.get_selected_app()
|
||||
system.notify_user('{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['downgraded']))
|
||||
util.notify_user('{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['downgraded']))
|
||||
|
||||
self.refresh_apps()
|
||||
|
||||
@@ -336,7 +336,7 @@ class ManageWindow(QWidget):
|
||||
self.tray_icon.verify_updates(notify_user=False)
|
||||
else:
|
||||
if self._can_notify_user():
|
||||
system.notify_user(self.locale_keys['notification.downgrade.failed'])
|
||||
util.notify_user(self.locale_keys['notification.downgrade.failed'])
|
||||
|
||||
self.change_update_state()
|
||||
self.checkbox_console.setChecked(True)
|
||||
@@ -486,14 +486,30 @@ class ManageWindow(QWidget):
|
||||
|
||||
def update_selected(self):
|
||||
if self.apps:
|
||||
requires_root = False
|
||||
|
||||
to_update = [app_v for app_v in self.apps if app_v.visible and app_v.update_checked]
|
||||
to_update = []
|
||||
|
||||
for app_v in self.apps:
|
||||
if app_v.visible and app_v.update_checked:
|
||||
to_update.append(app_v)
|
||||
|
||||
if self.manager.requires_root('update', app_v.model):
|
||||
requires_root = True
|
||||
|
||||
if to_update:
|
||||
self._handle_console_option(True)
|
||||
pwd = None
|
||||
|
||||
if not is_root() and requires_root:
|
||||
pwd, ok = ask_root_password(self.locale_keys)
|
||||
|
||||
if not ok:
|
||||
return
|
||||
|
||||
self._handle_console_option(True)
|
||||
self._begin_action(self.locale_keys['manage_window.status.upgrading'])
|
||||
self.thread_update.apps_to_update = to_update
|
||||
self.thread_update.root_password = pwd
|
||||
self.thread_update.start()
|
||||
|
||||
def _finish_update_selected(self, success: bool, updated: int):
|
||||
@@ -501,7 +517,7 @@ class ManageWindow(QWidget):
|
||||
|
||||
if success:
|
||||
if self._can_notify_user():
|
||||
system.notify_user('{} {}'.format(updated, self.locale_keys['notification.update_selected.success']))
|
||||
util.notify_user('{} {}'.format(updated, self.locale_keys['notification.update_selected.success']))
|
||||
|
||||
self.refresh_apps()
|
||||
|
||||
@@ -509,7 +525,7 @@ class ManageWindow(QWidget):
|
||||
self.tray_icon.verify_updates()
|
||||
else:
|
||||
if self._can_notify_user():
|
||||
system.notify_user(self.locale_keys['notification.update_selected.failed'])
|
||||
util.notify_user(self.locale_keys['notification.update_selected.failed'])
|
||||
|
||||
self.bt_upgrade.setEnabled(True)
|
||||
self.checkbox_console.setChecked(True)
|
||||
@@ -646,13 +662,13 @@ class ManageWindow(QWidget):
|
||||
if success:
|
||||
if self._can_notify_user():
|
||||
app = self.table_apps.get_selected_app()
|
||||
system.notify_user('{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['installed']))
|
||||
util.notify_user(msg='{} ({}) {}'.format(app.model.base_data.name, app.model.get_type(), self.locale_keys['installed']))
|
||||
|
||||
self.refresh_apps()
|
||||
else:
|
||||
if self._can_notify_user():
|
||||
app = self.table_apps.get_selected_app()
|
||||
system.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.install.failed']))
|
||||
util.notify_user('{}: {}'.format(app.model.base_data.name, self.locale_keys['notification.install.failed']))
|
||||
|
||||
self.checkbox_console.setChecked(True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user