Per app config

This commit is contained in:
Nikhil Badyal
2023-08-05 17:21:16 +05:30
parent b8c8983de8
commit bd5224c1a1
11 changed files with 222 additions and 307 deletions
+17 -6
View File
@@ -1,5 +1,6 @@
"""Downloader Class."""
import os
from pathlib import Path
from queue import PriorityQueue
from time import perf_counter
from typing import Any, Tuple
@@ -23,14 +24,20 @@ class Downloader(object):
self.config = config
self.patcher = patcher
def _download(self, url: str, file_name: str) -> None:
if (
os.path.exists(self.config.temp_folder.joinpath(file_name))
or self.config.dry_run
):
@staticmethod
def file_status_check(file_name: Path, dry_run: bool, url: str) -> bool:
"""Check if file already exists."""
if os.path.exists(file_name) or dry_run:
logger.debug(
f"Skipping download of {file_name}. File already exists or dry running."
f"Skipping download of {file_name} from {url}. File already exists or dry running."
)
return True
return False
def _download(self, url: str, file_name: str) -> None:
if self.file_status_check(
self.config.temp_folder.joinpath(file_name), self.config.dry_run, url
):
return
logger.info(f"Trying to download {file_name} from {url}")
self._QUEUE_LENGTH += 1
@@ -99,3 +106,7 @@ class Downloader(object):
self.specific_version(app, version)
else:
self.latest_version(app, **kwargs)
def direct_download(self, dl: str, file_name: str) -> None:
"""Download from DL."""
self._download(dl, file_name)