From e2de08fee39b7b4ad7362df32bec795675b63795 Mon Sep 17 00:00:00 2001 From: Nikhil Badyal Date: Sat, 2 Sep 2023 17:26:21 +0530 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20Moved=20extra=20downloader=20to?= =?UTF-8?q?=20download=20class?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 5 +++-- src/downloader/download.py | 24 ++++++++++++++++++++++++ src/utils.py | 28 ---------------------------- 3 files changed, 27 insertions(+), 30 deletions(-) diff --git a/main.py b/main.py index 46d0385..2dec4e52 100644 --- a/main.py +++ b/main.py @@ -6,10 +6,11 @@ from loguru import logger from src.app import APP from src.config import RevancedConfig +from src.downloader.download import Downloader from src.exceptions import AppNotFoundError, BuilderError, PatchesJsonLoadError, PatchingFailedError from src.parser import Parser from src.patches import Patches -from src.utils import check_java, extra_downloads +from src.utils import check_java def get_app(config: RevancedConfig, app_name: str) -> APP: @@ -24,7 +25,7 @@ def main() -> None: env = Env() env.read_env() config = RevancedConfig(env) - extra_downloads(config) + Downloader.extra_downloads(config) if not config.dry_run: check_java() diff --git a/src/downloader/download.py b/src/downloader/download.py index 652ef11..4c2eecc 100644 --- a/src/downloader/download.py +++ b/src/downloader/download.py @@ -132,3 +132,27 @@ class Downloader(object): def direct_download(self: Self, dl: str, file_name: str) -> None: """Download from DL.""" self._download(dl, file_name) + + @staticmethod + def extra_downloads(config: RevancedConfig) -> None: + """The function `extra_downloads` downloads extra files specified. + + Parameters + ---------- + config : RevancedConfig + The `config` parameter is an instance of the `RevancedConfig` class. It is used to provide + configuration settings for the download process. + """ + try: + for extra in config.extra_download_files: + url, file_name = extra.split("@") + file_name_without_extension, file_extension = os.path.splitext(file_name) + new_file_name = f"{file_name_without_extension}-output{file_extension}" + APP.download( + url, + config, + assets_filter=f".*{file_extension}", + file_name=new_file_name, + ) + except (ValueError, IndexError): + logger.info("Unable to download extra file. Provide input in url@name.apk format.") diff --git a/src/utils.py b/src/utils.py index f55bc59..caef0db 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,5 +1,4 @@ """Utilities.""" -import os import re import subprocess import sys @@ -10,7 +9,6 @@ import requests from loguru import logger from requests import Response, Session -from src.config import RevancedConfig from src.downloader.sources import APK_MIRROR_APK_CHECK from src.downloader.utils import status_code_200 from src.exceptions import ScrapingError @@ -173,32 +171,6 @@ def check_java() -> None: sys.exit(-1) -def extra_downloads(config: RevancedConfig) -> None: - """The function `extra_downloads` downloads extra files specified. - - Parameters - ---------- - config : RevancedConfig - The `config` parameter is an instance of the `RevancedConfig` class. It is used to provide - configuration settings for the download process. - """ - from src.app import APP - - try: - for extra in config.extra_download_files: - url, file_name = extra.split("@") - file_name_without_extension, file_extension = os.path.splitext(file_name) - new_file_name = f"{file_name_without_extension}-output{file_extension}" - APP.download( - url, - config, - assets_filter=f".*{file_extension}", - file_name=new_file_name, - ) - except (ValueError, IndexError): - logger.info("Unable to download extra file. Provide input in url@name.apk format.") - - def delete_old_changelog() -> None: """The function `delete_old_changelog` deleted old changelog file.""" Path(changelog_file).unlink(missing_ok=True)