mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 04:44:15 +02:00
[feature][arch] supporting multi-threaded download for repository packages
This commit is contained in:
@@ -6,12 +6,17 @@ from bauh.api.abstract.handler import ProcessWatcher
|
||||
class FileDownloader(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def download(self, file_url: str, watcher: ProcessWatcher, output_path: str, cwd: str) -> bool:
|
||||
def download(self, file_url: str, watcher: ProcessWatcher, output_path: str, cwd: str, root_password: str = None, substatus_prefix: str = None, display_file_size: bool = True, max_threads: int = None, known_size: int = None) -> bool:
|
||||
"""
|
||||
:param file_url:
|
||||
:param watcher:
|
||||
:param output_path: the downloaded file output path. Leave None for the current directory and the same file name
|
||||
:param cwd: current working directory. Leave None if does not matter.
|
||||
:param root_password: (if the output directory is protected)
|
||||
:param substatus_prefix: custom substatus prefix ('prefix downloading xpto')
|
||||
:param display_file_size: if the file size should be displayed on the substatus
|
||||
:param max_threads: maximum number of threads (only available for multi-threaded download)
|
||||
:param known_size: known file size
|
||||
:return: success / failure
|
||||
"""
|
||||
pass
|
||||
|
||||
@@ -89,11 +89,12 @@ class HttpClient:
|
||||
if size:
|
||||
return system.get_human_size_str(size)
|
||||
|
||||
def exists(self, url: str, session: bool = True) -> bool:
|
||||
params = {'url': url, 'allow_redirects': True, 'verify': False, 'timeout': 5}
|
||||
def exists(self, url: str, session: bool = True, timeout: int = 5) -> bool:
|
||||
params = {'url': url, 'allow_redirects': True, 'verify': False, 'timeout': timeout}
|
||||
if session:
|
||||
res = self.session.head(**params)
|
||||
else:
|
||||
res = self.session.get(**params)
|
||||
|
||||
return res.status_code in (200, 403)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user