mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-07 07:04:16 +02:00
arch:using axel to pre-download source file | info window handling list attributes better
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import logging
|
||||
import platform
|
||||
import sys
|
||||
|
||||
from bauh.api.abstract.cache import MemoryCacheFactory
|
||||
from bauh.api.abstract.disk import DiskCacheLoaderFactory
|
||||
from bauh.api.abstract.download import FileDownloader
|
||||
from bauh.api.http import HttpClient
|
||||
|
||||
|
||||
@@ -10,7 +12,7 @@ class ApplicationContext:
|
||||
|
||||
def __init__(self, disk_cache: bool, download_icons: bool, http_client: HttpClient, app_root_dir: str, i18n: dict,
|
||||
cache_factory: MemoryCacheFactory, disk_loader_factory: DiskCacheLoaderFactory,
|
||||
logger: logging.Logger):
|
||||
logger: logging.Logger, file_downloader: FileDownloader):
|
||||
"""
|
||||
:param disk_cache: if package data should be cached to disk
|
||||
:param download_icons: if packages icons should be downloaded
|
||||
@@ -20,6 +22,7 @@ class ApplicationContext:
|
||||
:param cache_factory:
|
||||
:param disk_loader_factory:
|
||||
:param logger: a logger instance
|
||||
:param file_downloader:
|
||||
"""
|
||||
self.disk_cache = disk_cache
|
||||
self.download_icons = download_icons
|
||||
@@ -30,3 +33,8 @@ class ApplicationContext:
|
||||
self.disk_loader_factory = disk_loader_factory
|
||||
self.logger = logger
|
||||
self.linux_distro = platform.linux_distribution()
|
||||
self.file_downloader = file_downloader
|
||||
self.arch_x86_64 = sys.maxsize > 2**32
|
||||
|
||||
def is_system_x86_64(self):
|
||||
return self.arch_x86_64
|
||||
|
||||
21
bauh/api/abstract/download.py
Normal file
21
bauh/api/abstract/download.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
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:
|
||||
"""
|
||||
: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.
|
||||
:return: success / failure
|
||||
"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def is_multithreaded(self) -> bool:
|
||||
pass
|
||||
@@ -38,3 +38,13 @@ class HttpClient:
|
||||
def get_json(self, url: str):
|
||||
res = self.get(url)
|
||||
return res.json() if res else None
|
||||
|
||||
def get_content_length(self, url: str) -> int:
|
||||
"""
|
||||
:param url:
|
||||
:return:
|
||||
"""
|
||||
res = self.session.head(url)
|
||||
|
||||
if res.status_code == 200:
|
||||
return res.headers['content-length']
|
||||
|
||||
Reference in New Issue
Block a user