mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-09 01:44:15 +02:00
improving install api
This commit is contained in:
@@ -3,6 +3,7 @@ from threading import Thread
|
|||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
|
|
||||||
from bauh_api.abstract.controller import ApplicationManager
|
from bauh_api.abstract.controller import ApplicationManager
|
||||||
|
from bauh_api.abstract.handler import ProcessHandler
|
||||||
from bauh_api.abstract.model import Application, ApplicationUpdate
|
from bauh_api.abstract.model import Application, ApplicationUpdate
|
||||||
from bauh_api.util.disk import DiskCacheLoader
|
from bauh_api.util.disk import DiskCacheLoader
|
||||||
from bauh_api.util.disk import DiskCacheLoaderFactory
|
from bauh_api.util.disk import DiskCacheLoaderFactory
|
||||||
@@ -119,9 +120,6 @@ class GenericApplicationManager(ApplicationManager):
|
|||||||
|
|
||||||
return installed
|
return installed
|
||||||
|
|
||||||
def can_downgrade(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def downgrade_app(self, app: Application, root_password: str) -> SystemProcess:
|
def downgrade_app(self, app: Application, root_password: str) -> SystemProcess:
|
||||||
man = self._get_manager_for(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
@@ -148,11 +146,11 @@ class GenericApplicationManager(ApplicationManager):
|
|||||||
if man:
|
if man:
|
||||||
return man.uninstall(app, root_password)
|
return man.uninstall(app, root_password)
|
||||||
|
|
||||||
def install(self, app: Application, root_password: str) -> SystemProcess:
|
def install(self, app: Application, root_password: str, handler: ProcessHandler) -> bool:
|
||||||
man = self._get_manager_for(app)
|
man = self._get_manager_for(app)
|
||||||
|
|
||||||
if man:
|
if man:
|
||||||
return man.install(app, root_password)
|
return man.install(app, root_password, handler)
|
||||||
|
|
||||||
def get_info(self, app: Application):
|
def get_info(self, app: Application):
|
||||||
man = self._get_manager_for(app)
|
man = self._get_manager_for(app)
|
||||||
|
|||||||
@@ -4,17 +4,18 @@ from typing import List
|
|||||||
|
|
||||||
import requests
|
import requests
|
||||||
from PyQt5.QtCore import QThread, pyqtSignal
|
from PyQt5.QtCore import QThread, pyqtSignal
|
||||||
|
from bauh_api.abstract.controller import ApplicationManager
|
||||||
|
from bauh_api.abstract.handler import ProcessHandler
|
||||||
from bauh_api.abstract.model import ApplicationStatus
|
from bauh_api.abstract.model import ApplicationStatus
|
||||||
from bauh_api.exception import NoInternetException
|
from bauh_api.exception import NoInternetException
|
||||||
from bauh_api.util.cache import Cache
|
from bauh_api.util.cache import Cache
|
||||||
from bauh_api.util.system import SystemProcess
|
from bauh_api.util.system import SystemProcess
|
||||||
|
|
||||||
from bauh_api.abstract.controller import ApplicationManager
|
|
||||||
from bauh.view.qt import dialog
|
from bauh.view.qt import dialog
|
||||||
from bauh.view.qt.view_model import ApplicationView
|
from bauh.view.qt.view_model import ApplicationView
|
||||||
|
|
||||||
|
|
||||||
class AsyncAction(QThread):
|
class AsyncAction(QThread, ProcessHandler):
|
||||||
|
|
||||||
def notify_subproc_outputs(self, proc: SystemProcess, signal) -> bool:
|
def notify_subproc_outputs(self, proc: SystemProcess, signal) -> bool:
|
||||||
"""
|
"""
|
||||||
@@ -26,6 +27,8 @@ class AsyncAction(QThread):
|
|||||||
|
|
||||||
success, already_succeeded = True, False
|
success, already_succeeded = True, False
|
||||||
|
|
||||||
|
proc.subproc.wait()
|
||||||
|
|
||||||
for output in proc.subproc.stdout:
|
for output in proc.subproc.stdout:
|
||||||
line = output.decode().strip()
|
line = output.decode().strip()
|
||||||
if line:
|
if line:
|
||||||
@@ -46,7 +49,8 @@ class AsyncAction(QThread):
|
|||||||
success = False
|
success = False
|
||||||
signal.emit(line)
|
signal.emit(line)
|
||||||
|
|
||||||
return success
|
proc.subproc.communicate()
|
||||||
|
return proc.subproc.returncode is None or proc.subproc.returncode == 0
|
||||||
|
|
||||||
|
|
||||||
class UpdateSelectedApps(AsyncAction):
|
class UpdateSelectedApps(AsyncAction):
|
||||||
@@ -224,8 +228,7 @@ class InstallApp(AsyncAction):
|
|||||||
success = False
|
success = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = self.manager.install(self.app.model, self.root_password)
|
success = self.manager.install(self.app.model, self.root_password, self)
|
||||||
success = self.notify_subproc_outputs(process, self.signal_output)
|
|
||||||
|
|
||||||
if success and self.disk_cache:
|
if success and self.disk_cache:
|
||||||
self.app.model.installed = True
|
self.app.model.installed = True
|
||||||
@@ -242,6 +245,13 @@ class InstallApp(AsyncAction):
|
|||||||
self.signal_finished.emit(self.app if success else None)
|
self.signal_finished.emit(self.app if success else None)
|
||||||
self.app = None
|
self.app = None
|
||||||
|
|
||||||
|
def handle(self, proc: SystemProcess) -> bool:
|
||||||
|
return self.notify_subproc_outputs(proc, self.signal_output)
|
||||||
|
|
||||||
|
def notify(self, msg: str):
|
||||||
|
if msg:
|
||||||
|
self.signal_output.emit(msg)
|
||||||
|
|
||||||
|
|
||||||
class AnimateProgress(QThread):
|
class AnimateProgress(QThread):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user