diff --git a/modules/auto_update.py b/modules/auto_update.py index 3f76ca0..16d1038 100644 --- a/modules/auto_update.py +++ b/modules/auto_update.py @@ -9,20 +9,56 @@ from alive_progress import alive_bar # Import Local Libraries -from main import version +from .storage import __version__ as VERSION +from .storage import __user_agent__ as USER_AGENT from .logger import Logger -from .pretty_print import error, ok -class AutoUpdate: - def __init__(self): +class AutoUpdateChecker: + + def __init__(self) -> None: + """ + Initializes the AutoUpdateChecker class. + + This constructor sets the initial values for the repository URL, user agent, and tool version. + The repository URL is set to the GitHub API endpoint for the latest releases of the mul-tor repository. + The user agent is set to the value of the USER_AGENT constant from the storage module. + The tool version is set to the value of the VERSION constant from the storage module. + + Parameters: + None + + Returns: + None + """ + self.repository_url: str = "https://api.github.com/repos/Official-Husko/mul-tor/releases/latest" + self.user_agent: str = USER_AGENT + self.tool_version: str = VERSION + + def _fetch_repo_details(self) -> dict: + headers = { + "User-Agent": self.user_agent, + "Accept": "application/vnd.github+json", + "X-GitHub-Api-Version": "2022-11-28" + } + + response = requests.get(self.repository_url, headers=headers, timeout=15) + + if not response.status_code == 200: + raise Exception(response.status_code) + + return response + + def _extract_repo_details(self, request_response: dict): + + return request_response.get("tag_name", "0.0.1") def _checker(self): try: headers = { - "User-Agent":f"mul-tor/{version} (by Official Husko on GitHub)", + "User-Agent":f"mul-tor/{VERSION} (by Official Husko on GitHub)", "Accept": "application/vnd.github+json", "X-GitHub-Api-Version": "2022-11-28" } @@ -31,7 +67,7 @@ def _checker(self): repo_version = req.get("tag_name").replace("v", "") download_link = req["assets"][0]["browser_download_url"] - if str(version) < repo_version: + if str(VERSION) < repo_version: print(colored("UPDATE AVAILABLE! ", "red", attrs=["blink"])) body = req.get("body") @@ -53,7 +89,7 @@ def _checker(self): print("") decision = amount_answers.get("selection") if decision == "Yes": - r = requests.get(download_link, headers={"User-Agent":f"mul-tor/{version} (by Official Husko on GitHub)"}, timeout=60, stream=True) + r = requests.get(download_link, headers={"User-Agent":f"mul-tor/{VERSION} (by Official Husko on GitHub)"}, timeout=60, stream=True) with alive_bar(int(int(r.headers.get('content-length')) / 1024 + 1)) as progress_bar: progress_bar.text = f'-> Downloading Update {repo_version}, please wait...' file = open(f"mul-tor-{repo_version}.exe", 'wb') @@ -76,7 +112,7 @@ def _checker(self): if not os.path.exists("outdated"): with open("outdated", "a", encoding="utf-8") as mark_outdated: mark_outdated.close() - elif str(version) >= repo_version: + elif str(VERSION) >= repo_version: try: os.remove("outdated") except Exception: diff --git a/modules/sites/buzzheavier.py b/modules/buzzheavier.py similarity index 100% rename from modules/sites/buzzheavier.py rename to modules/buzzheavier.py diff --git a/modules/utils/file_hash_calculator.py b/modules/file_hash_calculator.py similarity index 100% rename from modules/utils/file_hash_calculator.py rename to modules/file_hash_calculator.py diff --git a/modules/utils/file_size_calculator.py b/modules/file_size_calculator.py similarity index 100% rename from modules/utils/file_size_calculator.py rename to modules/file_size_calculator.py diff --git a/modules/utils/logger.py b/modules/logger.py similarity index 96% rename from modules/utils/logger.py rename to modules/logger.py index 133985d..00fd2de 100644 --- a/modules/utils/logger.py +++ b/modules/logger.py @@ -8,7 +8,7 @@ from termcolor import colored # Import Local Libraries -from .utils/storage import __version__ as version +from .storage import __version__ as version from .pretty_print import PrettyPrint class Logger: diff --git a/modules/pretty_print.py b/modules/pretty_print.py index c5918c6..fe24c96 100644 --- a/modules/pretty_print.py +++ b/modules/pretty_print.py @@ -1,6 +1,10 @@ from termcolor import colored class PrettyPrint: + """ + Initialize the PrettyPrint object by assigning colored strings to different attributes. + """ + def __init__(self) -> None: self.major = str(colored(f"[{colored('!!!', 'red')}]")) self.error = str(colored(f"[{colored('!', 'red')}]")) diff --git a/modules/utils/storage.py b/modules/storage.py similarity index 100% rename from modules/utils/storage.py rename to modules/storage.py