[improvement][settings] only displaying available multi-threaded download clients

This commit is contained in:
Vinícius Moreira
2020-05-28 11:36:54 -03:00
parent c8f1e0b1f0
commit 5340070b3a
12 changed files with 70 additions and 28 deletions

View File

@@ -30,7 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
</p> </p>
- Settings - Settings
- [axel](https://github.com/axel-download-accelerator/axel) added as an alternative multi-threaded download tool. The tool can be defined through the new field **Multi-threaded download tool** on the settings window **Advanced** tab - [axel](https://github.com/axel-download-accelerator/axel) added as an alternative multi-threaded download tool. The tool can be defined through the new field **Multi-threaded download tool** on the settings window **Advanced** tab (check **Default** for bauh to decide which one to use)
<p align="center"> <p align="center">
<img src="https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/releases/0.9.4/mthread_tool.png"> <img src="https://raw.githubusercontent.com/vinifmor/bauh/staging/pictures/releases/0.9.4/mthread_tool.png">
</p> </p>

View File

@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing import Iterable from typing import Iterable, List
from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.handler import ProcessWatcher
@@ -33,3 +33,11 @@ class FileDownloader(ABC):
@abstractmethod @abstractmethod
def get_supported_multithreaded_clients(self) -> Iterable[str]: def get_supported_multithreaded_clients(self) -> Iterable[str]:
pass pass
@abstractmethod
def is_multithreaded_client_available(self, name: str) -> bool:
pass
@abstractmethod
def list_available_multithreaded_clients(self) -> List[str]:
pass

View File

@@ -5,7 +5,7 @@ import time
import traceback import traceback
from math import floor from math import floor
from threading import Thread from threading import Thread
from typing import Iterable from typing import Iterable, List
from bauh.api.abstract.download import FileDownloader from bauh.api.abstract.download import FileDownloader
from bauh.api.abstract.handler import ProcessWatcher from bauh.api.abstract.handler import ProcessWatcher
@@ -24,7 +24,7 @@ class AdaptableFileDownloader(FileDownloader):
self.multithread_enabled = multithread_enabled self.multithread_enabled = multithread_enabled
self.i18n = i18n self.i18n = i18n
self.http_client = http_client self.http_client = http_client
self.supported_multithread_clients = {'aria2', 'axel'} self.supported_multithread_clients = ['aria2', 'axel']
self.multithread_client = multithread_client self.multithread_client = multithread_client
@staticmethod @staticmethod
@@ -184,22 +184,39 @@ class AdaptableFileDownloader(FileDownloader):
return success return success
def is_multithreaded(self) -> bool: def is_multithreaded(self) -> bool:
return self.multithread_enabled and (self.is_aria2c_available() or self.is_axel_available()) return bool(self.get_available_multithreaded_tool())
def get_available_multithreaded_tool(self) -> str: def get_available_multithreaded_tool(self) -> str:
if self.multithread_enabled: if self.multithread_enabled:
if self.multithread_client is None: if self.multithread_client is None or self.multithread_client not in self.supported_multithread_clients:
if self.is_aria2c_available(): for client in self.supported_multithread_clients:
return 'aria2' if self.is_multithreaded_client_available(client):
elif self.is_axel_available(): return client
return 'axel' else:
elif (self.multithread_client == 'aria2' or self.multithread_client not in self.get_supported_multithreaded_clients()) and self.is_aria2c_available(): possible_clients = {*self.supported_multithread_clients}
return 'aria2'
elif self.is_axel_available(): if self.is_multithreaded_client_available(self.multithread_client):
return 'axel' return self.multithread_client
else:
possible_clients.remove(self.multithread_client)
for client in possible_clients:
if self.is_multithreaded_client_available(client):
return client
def can_work(self) -> bool: def can_work(self) -> bool:
return self.is_wget_available() or self.is_multithreaded() return self.is_wget_available() or self.is_multithreaded()
def get_supported_multithreaded_clients(self) -> Iterable[str]: def get_supported_multithreaded_clients(self) -> Iterable[str]:
return self.supported_multithread_clients return self.supported_multithread_clients
def is_multithreaded_client_available(self, name: str) -> bool:
if name == 'aria2':
return self.is_aria2c_available()
elif name == 'axel':
return self.is_axel_available()
else:
return False
def list_available_multithreaded_clients(self) -> List[str]:
return [c for c in self.supported_multithread_clients if self.is_multithreaded_client_available(c)]

View File

@@ -121,24 +121,33 @@ class GenericSettingsManager:
max_width=default_width, max_width=default_width,
value=core_config['download']['multithreaded']) value=core_config['download']['multithreaded'])
supported_mthread_clients = self.file_downloader.get_supported_multithreaded_clients() select_mthread_client = self._gen_multithread_client_select(core_config, default_width)
mthread_client_opts = [(self.i18n['default'].capitalize(), None, None)]
mthread_client_opts.extend(((d, d, None) for d in supported_mthread_clients))
current_mthread_client = core_config['download']['multithreaded_client']
if current_mthread_client not in supported_mthread_clients:
current_mthread_client = None
select_mthread_client = self._gen_select(label=self.i18n['core.config.download.multithreaded_client'],
tip=self.i18n['core.config.download.multithreaded_client.tip'],
id_="mthread_client",
max_width=default_width,
opts=mthread_client_opts,
value=current_mthread_client)
sub_comps = [FormComponent([select_dmthread, select_mthread_client, select_trim_up, select_dep_check, input_data_exp, input_icon_exp], spaces=False)] sub_comps = [FormComponent([select_dmthread, select_mthread_client, select_trim_up, select_dep_check, input_data_exp, input_icon_exp], spaces=False)]
return TabComponent(self.i18n['core.config.tab.advanced'].capitalize(), PanelComponent(sub_comps), None, 'core.adv') return TabComponent(self.i18n['core.config.tab.advanced'].capitalize(), PanelComponent(sub_comps), None, 'core.adv')
def _gen_multithread_client_select(self, core_config: dict, default_width: int) -> SingleSelectComponent:
available_mthread_clients = self.file_downloader.list_available_multithreaded_clients()
available_mthread_clients.sort()
default_i18n_key = 'default' if available_mthread_clients else 'core.config.download.multithreaded_client.none'
mthread_client_opts = [(self.i18n[default_i18n_key].capitalize(), None, None)]
for client in available_mthread_clients:
mthread_client_opts.append((client, client, None))
current_mthread_client = core_config['download']['multithreaded_client']
if current_mthread_client not in available_mthread_clients:
current_mthread_client = None
return self._gen_select(label=self.i18n['core.config.download.multithreaded_client'],
tip=self.i18n['core.config.download.multithreaded_client.tip'],
id_="mthread_client",
max_width=default_width,
opts=mthread_client_opts,
value=current_mthread_client)
def _gen_tray_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent: def _gen_tray_settings(self, core_config: dict, screen_width: int, screen_height: int) -> TabComponent:
default_width = floor(0.22 * screen_width) default_width = floor(0.22 * screen_width)

View File

@@ -194,6 +194,7 @@ core.config.download.icons.tip=If the application icons should be downloaded and
core.config.download.multithreaded=Multithreaded download core.config.download.multithreaded=Multithreaded download
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with threads (faster). core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with threads (faster).
core.config.download.multithreaded_client=Multi-threaded download tool core.config.download.multithreaded_client=Multi-threaded download tool
core.config.download.multithreaded_client.none=None available
core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work. core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work.
core.config.downloads=downloads core.config.downloads=downloads
core.config.locale.label=language core.config.locale.label=language

View File

@@ -193,6 +193,7 @@ core.config.download.icons.tip=Falls aktiviert werden die Anwendungs-Icons in de
core.config.download.multithreaded=Paralleler Download core.config.download.multithreaded=Paralleler Download
core.config.download.multithreaded.tip=Falls aktiviert werden Downloads parallel (mit mehreren Threads) heruntergeladen. core.config.download.multithreaded.tip=Falls aktiviert werden Downloads parallel (mit mehreren Threads) heruntergeladen.
core.config.download.multithreaded_client=Multi-threaded download tool core.config.download.multithreaded_client=Multi-threaded download tool
core.config.download.multithreaded_client.none=None available
core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work. core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work.
core.config.downloads=Downloads core.config.downloads=Downloads
core.config.locale.label=Sprache core.config.locale.label=Sprache

View File

@@ -193,6 +193,7 @@ core.config.download.icons=Download icons
core.config.download.multithreaded=Multi-threaded download core.config.download.multithreaded=Multi-threaded download
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with threads (faster). core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with threads (faster).
core.config.download.multithreaded_client=Multi-threaded download tool core.config.download.multithreaded_client=Multi-threaded download tool
core.config.download.multithreaded_client.none=None available
core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work. core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work.
core.config.downloads=downloads core.config.downloads=downloads
core.config.locale.label=language core.config.locale.label=language

View File

@@ -194,6 +194,7 @@ core.config.download.icons.tip=Si los íconos de las aplicaciones se deben desca
core.config.download.multithreaded=Descarga segmentada core.config.download.multithreaded=Descarga segmentada
core.config.download.multithreaded.tip=Si las aplicaciones, paquetes y archivos deben descargarse con una herramienta que usa segmentación / threads (más rápido). core.config.download.multithreaded.tip=Si las aplicaciones, paquetes y archivos deben descargarse con una herramienta que usa segmentación / threads (más rápido).
core.config.download.multithreaded_client=Herramienta para descarga segmentada core.config.download.multithreaded_client=Herramienta para descarga segmentada
core.config.download.multithreaded_client.none=Ninguna disponible
core.config.download.multithreaded_client.tip=La herramienta que debe usarse para descargas segmentadas. Ella debe estar instalada en el sistema para que esta configuración funcione. core.config.download.multithreaded_client.tip=La herramienta que debe usarse para descargas segmentadas. Ella debe estar instalada en el sistema para que esta configuración funcione.
core.config.downloads=downloads core.config.downloads=downloads
core.config.locale.label=idioma core.config.locale.label=idioma

View File

@@ -193,6 +193,7 @@ core.config.download.icons.tip=If the application icons should be downloaded and
core.config.download.multithreaded=Multithreaded download core.config.download.multithreaded=Multithreaded download
core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with threads (faster). core.config.download.multithreaded.tip=Whether applications, packages and files should be downloaded with a tool that works with threads (faster).
core.config.download.multithreaded_client=Multi-threaded download tool core.config.download.multithreaded_client=Multi-threaded download tool
core.config.download.multithreaded_client.none=None available
core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work. core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work.
core.config.downloads=downloads core.config.downloads=downloads
core.config.locale.label=language core.config.locale.label=language

View File

@@ -193,6 +193,7 @@ core.config.download.icons=Baixar ícones
core.config.download.multithreaded.tip=Se os aplicativos, pacotes e arquivos devem ser baixados através de uma ferramenta que trabalha com segmentação / threads (mais rápido). core.config.download.multithreaded.tip=Se os aplicativos, pacotes e arquivos devem ser baixados através de uma ferramenta que trabalha com segmentação / threads (mais rápido).
core.config.download.multithreaded=Download segmentado core.config.download.multithreaded=Download segmentado
core.config.download.multithreaded_client=Ferramenta para download segmentado core.config.download.multithreaded_client=Ferramenta para download segmentado
core.config.download.multithreaded_client.none=Nenhuma disponível
core.config.download.multithreaded_client.tip=A ferramenta que deve ser utilizada para downloads segmentados. Ela precisa estar instalada no sistema para que essa configuração funcione. core.config.download.multithreaded_client.tip=A ferramenta que deve ser utilizada para downloads segmentados. Ela precisa estar instalada no sistema para que essa configuração funcione.
core.config.downloads=downloads core.config.downloads=downloads
core.config.locale.label=idioma core.config.locale.label=idioma

View File

@@ -193,6 +193,7 @@ core.config.download.icons.tip=Загружать иконки приложен
core.config.download.multithreaded=Многопоточная загрузка core.config.download.multithreaded=Многопоточная загрузка
core.config.download.multithreaded.tip=Следует ли загружать приложения, пакеты и файлы с помощью инструмента, который работает с потоками (быстрее). core.config.download.multithreaded.tip=Следует ли загружать приложения, пакеты и файлы с помощью инструмента, который работает с потоками (быстрее).
core.config.download.multithreaded_client=Multi-threaded download tool core.config.download.multithreaded_client=Multi-threaded download tool
core.config.download.multithreaded_client.none=None available
core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work. core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work.
core.config.downloads=downloads core.config.downloads=downloads
core.config.locale.label=Язык core.config.locale.label=Язык

View File

@@ -193,6 +193,7 @@ core.config.download.icons=Simgeleri indir
core.config.download.multithreaded.tip=Uygulamaların, paketlerin ve dosyaların iş parçacıklarıyla (daha hızlı) çalışan bir araçla indirilip indirilmeyeceği. core.config.download.multithreaded.tip=Uygulamaların, paketlerin ve dosyaların iş parçacıklarıyla (daha hızlı) çalışan bir araçla indirilip indirilmeyeceği.
core.config.download.multithreaded=Çoklu parçalı indirme core.config.download.multithreaded=Çoklu parçalı indirme
core.config.download.multithreaded_client=Multi-threaded download tool core.config.download.multithreaded_client=Multi-threaded download tool
core.config.download.multithreaded_client.none=None available
core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work. core.config.download.multithreaded_client.tip=The download tool that should be used for multi-threaded downloads. It must be installed on the system for this configuration to work.
core.config.downloads=indirilenler core.config.downloads=indirilenler
core.config.locale.label=dil core.config.locale.label=dil