From 5340070b3a8f6d327c37efa2fd4d4796beb8d1ea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Vin=C3=ADcius=20Moreira?=
Date: Thu, 28 May 2020 11:36:54 -0300
Subject: [PATCH] [improvement][settings] only displaying available
multi-threaded download clients
---
CHANGELOG.md | 2 +-
bauh/api/abstract/download.py | 10 ++++++++-
bauh/view/core/downloader.py | 41 +++++++++++++++++++++++++----------
bauh/view/core/settings.py | 37 +++++++++++++++++++------------
bauh/view/resources/locale/ca | 1 +
bauh/view/resources/locale/de | 1 +
bauh/view/resources/locale/en | 1 +
bauh/view/resources/locale/es | 1 +
bauh/view/resources/locale/it | 1 +
bauh/view/resources/locale/pt | 1 +
bauh/view/resources/locale/ru | 1 +
bauh/view/resources/locale/tr | 1 +
12 files changed, 70 insertions(+), 28 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a512ddaf..00b01aec 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -30,7 +30,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- 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)
diff --git a/bauh/api/abstract/download.py b/bauh/api/abstract/download.py
index a90a8dd1..f9359198 100644
--- a/bauh/api/abstract/download.py
+++ b/bauh/api/abstract/download.py
@@ -1,5 +1,5 @@
from abc import ABC, abstractmethod
-from typing import Iterable
+from typing import Iterable, List
from bauh.api.abstract.handler import ProcessWatcher
@@ -33,3 +33,11 @@ class FileDownloader(ABC):
@abstractmethod
def get_supported_multithreaded_clients(self) -> Iterable[str]:
pass
+
+ @abstractmethod
+ def is_multithreaded_client_available(self, name: str) -> bool:
+ pass
+
+ @abstractmethod
+ def list_available_multithreaded_clients(self) -> List[str]:
+ pass
diff --git a/bauh/view/core/downloader.py b/bauh/view/core/downloader.py
index 7aecfa0e..d01b5ccc 100644
--- a/bauh/view/core/downloader.py
+++ b/bauh/view/core/downloader.py
@@ -5,7 +5,7 @@ import time
import traceback
from math import floor
from threading import Thread
-from typing import Iterable
+from typing import Iterable, List
from bauh.api.abstract.download import FileDownloader
from bauh.api.abstract.handler import ProcessWatcher
@@ -24,7 +24,7 @@ class AdaptableFileDownloader(FileDownloader):
self.multithread_enabled = multithread_enabled
self.i18n = i18n
self.http_client = http_client
- self.supported_multithread_clients = {'aria2', 'axel'}
+ self.supported_multithread_clients = ['aria2', 'axel']
self.multithread_client = multithread_client
@staticmethod
@@ -184,22 +184,39 @@ class AdaptableFileDownloader(FileDownloader):
return success
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:
if self.multithread_enabled:
- if self.multithread_client is None:
- if self.is_aria2c_available():
- return 'aria2'
- elif self.is_axel_available():
- return 'axel'
- elif (self.multithread_client == 'aria2' or self.multithread_client not in self.get_supported_multithreaded_clients()) and self.is_aria2c_available():
- return 'aria2'
- elif self.is_axel_available():
- return 'axel'
+ if self.multithread_client is None or self.multithread_client not in self.supported_multithread_clients:
+ for client in self.supported_multithread_clients:
+ if self.is_multithreaded_client_available(client):
+ return client
+ else:
+ possible_clients = {*self.supported_multithread_clients}
+
+ if self.is_multithreaded_client_available(self.multithread_client):
+ 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:
return self.is_wget_available() or self.is_multithreaded()
def get_supported_multithreaded_clients(self) -> Iterable[str]:
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)]
diff --git a/bauh/view/core/settings.py b/bauh/view/core/settings.py
index 04e3d8d3..e6e1b365 100644
--- a/bauh/view/core/settings.py
+++ b/bauh/view/core/settings.py
@@ -121,24 +121,33 @@ class GenericSettingsManager:
max_width=default_width,
value=core_config['download']['multithreaded'])
- supported_mthread_clients = self.file_downloader.get_supported_multithreaded_clients()
- 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)
+ select_mthread_client = self._gen_multithread_client_select(core_config, default_width)
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')
+ 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:
default_width = floor(0.22 * screen_width)
diff --git a/bauh/view/resources/locale/ca b/bauh/view/resources/locale/ca
index 982535af..bdcba06a 100644
--- a/bauh/view/resources/locale/ca
+++ b/bauh/view/resources/locale/ca
@@ -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.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.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.downloads=downloads
core.config.locale.label=language
diff --git a/bauh/view/resources/locale/de b/bauh/view/resources/locale/de
index a0736c4e..0c296604 100644
--- a/bauh/view/resources/locale/de
+++ b/bauh/view/resources/locale/de
@@ -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.tip=Falls aktiviert werden Downloads parallel (mit mehreren Threads) heruntergeladen.
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.downloads=Downloads
core.config.locale.label=Sprache
diff --git a/bauh/view/resources/locale/en b/bauh/view/resources/locale/en
index c1ad3e2c..bd093258 100644
--- a/bauh/view/resources/locale/en
+++ b/bauh/view/resources/locale/en
@@ -193,6 +193,7 @@ core.config.download.icons=Download icons
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_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.downloads=downloads
core.config.locale.label=language
diff --git a/bauh/view/resources/locale/es b/bauh/view/resources/locale/es
index ae2714ec..1fa41b26 100644
--- a/bauh/view/resources/locale/es
+++ b/bauh/view/resources/locale/es
@@ -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.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.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.downloads=downloads
core.config.locale.label=idioma
diff --git a/bauh/view/resources/locale/it b/bauh/view/resources/locale/it
index 252a2427..3f969129 100644
--- a/bauh/view/resources/locale/it
+++ b/bauh/view/resources/locale/it
@@ -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.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.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.downloads=downloads
core.config.locale.label=language
diff --git a/bauh/view/resources/locale/pt b/bauh/view/resources/locale/pt
index 82da564c..68c7405f 100644
--- a/bauh/view/resources/locale/pt
+++ b/bauh/view/resources/locale/pt
@@ -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=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.downloads=downloads
core.config.locale.label=idioma
diff --git a/bauh/view/resources/locale/ru b/bauh/view/resources/locale/ru
index 1794d428..12fb1584 100644
--- a/bauh/view/resources/locale/ru
+++ b/bauh/view/resources/locale/ru
@@ -193,6 +193,7 @@ core.config.download.icons.tip=Загружать иконки приложен
core.config.download.multithreaded=Многопоточная загрузка
core.config.download.multithreaded.tip=Следует ли загружать приложения, пакеты и файлы с помощью инструмента, который работает с потоками (быстрее).
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.downloads=downloads
core.config.locale.label=Язык
diff --git a/bauh/view/resources/locale/tr b/bauh/view/resources/locale/tr
index 993f9e82..d75fc553 100644
--- a/bauh/view/resources/locale/tr
+++ b/bauh/view/resources/locale/tr
@@ -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=Çoklu parçalı indirme
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.downloads=indirilenler
core.config.locale.label=dil