improving install api

This commit is contained in:
Vinicius Moreira
2019-08-13 14:54:49 -03:00
parent bb85793e0b
commit d13fb7025c
2 changed files with 18 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ from threading import Thread
from typing import List, Dict
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.util.disk import DiskCacheLoader
from bauh_api.util.disk import DiskCacheLoaderFactory
@@ -119,9 +120,6 @@ class GenericApplicationManager(ApplicationManager):
return installed
def can_downgrade(self):
return True
def downgrade_app(self, app: Application, root_password: str) -> SystemProcess:
man = self._get_manager_for(app)
@@ -148,11 +146,11 @@ class GenericApplicationManager(ApplicationManager):
if man:
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)
if man:
return man.install(app, root_password)
return man.install(app, root_password, handler)
def get_info(self, app: Application):
man = self._get_manager_for(app)

View File

@@ -4,17 +4,18 @@ from typing import List
import requests
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.exception import NoInternetException
from bauh_api.util.cache import Cache
from bauh_api.util.system import SystemProcess
from bauh_api.abstract.controller import ApplicationManager
from bauh.view.qt import dialog
from bauh.view.qt.view_model import ApplicationView
class AsyncAction(QThread):
class AsyncAction(QThread, ProcessHandler):
def notify_subproc_outputs(self, proc: SystemProcess, signal) -> bool:
"""
@@ -26,6 +27,8 @@ class AsyncAction(QThread):
success, already_succeeded = True, False
proc.subproc.wait()
for output in proc.subproc.stdout:
line = output.decode().strip()
if line:
@@ -46,7 +49,8 @@ class AsyncAction(QThread):
success = False
signal.emit(line)
return success
proc.subproc.communicate()
return proc.subproc.returncode is None or proc.subproc.returncode == 0
class UpdateSelectedApps(AsyncAction):
@@ -224,8 +228,7 @@ class InstallApp(AsyncAction):
success = False
try:
process = self.manager.install(self.app.model, self.root_password)
success = self.notify_subproc_outputs(process, self.signal_output)
success = self.manager.install(self.app.model, self.root_password, self)
if success and self.disk_cache:
self.app.model.installed = True
@@ -242,6 +245,13 @@ class InstallApp(AsyncAction):
self.signal_finished.emit(self.app if success else 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):