arch:using axel to pre-download source file | info window handling list attributes better

This commit is contained in:
Vinicius Moreira
2019-09-22 01:01:11 -03:00
parent 0085f40cdf
commit 917c6ec5d7
18 changed files with 189 additions and 22 deletions

View File

@@ -218,7 +218,7 @@ class GenericSoftwareManager(SoftwareManager):
return False
finally:
tf = time.time()
self.logger.info('Installation of {} took {} seconds'.format(app, tf - ti))
self.logger.info('Installation of {}'.format(app) + 'took {0:.2f} minutes'.format((tf - ti)/60))
def get_info(self, app: SoftwarePackage):
man = self._get_manager_for(app)

View File

@@ -0,0 +1,53 @@
import logging
import time
from multiprocessing import cpu_count
from typing import List
from bauh.api.abstract.download import FileDownloader
from bauh.api.abstract.handler import ProcessWatcher
from bauh.commons.system import run_cmd, new_subprocess, ProcessHandler, SystemProcess
class AdaptableFileDownloader(FileDownloader):
def __init__(self, logger: logging.Logger, multithread_enabled: bool):
self.download_threads = cpu_count() * 2
self.logger = logger
self.multithread_enabled = multithread_enabled
def is_axel_available(self) -> bool:
return bool(run_cmd('which axel'))
def _get_download_command(self, url: str, output_path: str) -> List:
if self.is_multithreaded():
cmd = ['axel', '-k', '-n', str(self.download_threads), url]
if output_path:
cmd.append('-o')
cmd.append(output_path)
return cmd
cmd = ['wget', url]
if output_path:
cmd.append('-O')
cmd.append(output_path)
return cmd
def download(self, file_url: str, watcher: ProcessWatcher, output_path: str, cwd: str):
handler = ProcessHandler(watcher)
cmd = self._get_download_command(file_url, output_path)
self.logger.info('Downloading {}'.format(file_url))
watcher.print("[{}] downloading {}{}".format(cmd[0], file_url, " as {}".format(output_path) if output_path else ''))
ti = time.time()
res = handler.handle(SystemProcess(new_subprocess(cmd=cmd, cwd=cwd if cwd else '.')))
tf = time.time()
self.logger.info(file_url.split('/')[-1] + ' download took {0:.2f} minutes'.format((tf - ti) / 60))
return res
def is_multithreaded(self) -> bool:
return self.multithread_enabled and self.is_axel_available()

View File

@@ -12,7 +12,7 @@ class InfoDialog(QDialog):
def __init__(self, app: dict, icon_cache: MemoryCache, locale_keys: dict, screen_size: QSize()):
super(InfoDialog, self).__init__()
self.setWindowTitle(app['__app__'].model.name)
self.setWindowTitle(str(app['__app__']))
self.screen_size = screen_size
self.i18n = locale_keys
layout = QVBoxLayout()
@@ -50,7 +50,7 @@ class InfoDialog(QDialog):
i18n_key = app['__app__'].model.get_type() + '.info.' + attr.lower()
if isinstance(app[attr], list):
val = '\n'.join([str(e) for e in app[attr]])
val = '\n'.join(['* ' + str(e.strip()) for e in app[attr] if e])
else:
val = str(app[attr]).strip()

View File

@@ -1,5 +1,7 @@
import operator
import time
from functools import reduce
from pathlib import Path
from typing import List, Type, Set
from PyQt5.QtCore import QEvent, Qt, QSize, pyqtSignal
@@ -867,6 +869,18 @@ class ManageWindow(QWidget):
self.thread_install.start()
def _finish_install(self, pkgv: PackageView):
console_output = self.textarea_output.toPlainText()
if console_output:
log_path = '/tmp/bauh/logs/install/{}/{}'.format(pkgv.model.get_type(), pkgv.model.name)
try:
Path(log_path).mkdir(parents=True, exist_ok=True)
with open(log_path + '/{}.log'.format(int(time.time())), 'w+') as f:
f.write(console_output)
except:
self.textarea_output.appendPlainText("[warning] Could not write install log file to '{}'".format(log_path))
self.input_search.setText('')
self.finish_action()

View File

@@ -115,4 +115,5 @@ manage_window.settings.gems=Application types
style=style
style.change.title=Style change
style.change.question=To change the current style is necessary to restart {}. Proceed ?
manage_window.bt_settings.tooltip=Click here to open extra actions
manage_window.bt_settings.tooltip=Click here to open extra actions
downloading=Downloading

View File

@@ -117,4 +117,5 @@ manage_window.settings.gems=Tipos de aplicativos
style=estilo
style.change.title=Cambio de estilo
style.change.question=Para cambiar el estilo actual es necesario reiniciar {}. ¿Proceder?
manage_window.bt_settings.tooltip=Haga clic aquí para abrir acciones adicionales
manage_window.bt_settings.tooltip=Haga clic aquí para abrir acciones adicionales
downloading=Descargando

View File

@@ -117,4 +117,5 @@ manage_window.settings.gems=Tipos de aplicativos
style=estilo
style.change.title=Mudança de estilo
style.change.question=Para alterar o estilo atual é necessário reiniciar o {}. Continuar ?
manage_window.bt_settings.tooltip=Clique aqui para abrir ações adicionais
manage_window.bt_settings.tooltip=Clique aqui para abrir ações adicionais
downloading=Baixando