From b89e6c20ce3f6a70eb3f290b4ed39bea356fedcc Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Sun, 19 Jan 2025 11:29:48 +0300 Subject: [PATCH] Refactor self_update function in checker.py to accept a logger parameter for improved logging. This change enhances the update process by providing consistent logging messages for update checks, successes, and errors, thereby improving the clarity and maintainability of the script's update functionality. --- checker.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/checker.py b/checker.py index 07f3a25..585b8da 100644 --- a/checker.py +++ b/checker.py @@ -27,7 +27,8 @@ import colorama import logging import socket -def self_update(): +def self_update(logger): + logger.info("Checking for updates..") script_path = os.path.abspath(__file__) update_url = "https://gitea.vvzvlad.xyz/vvzvlad/ritual/raw/branch/main-22aug/checker.py" try: @@ -40,14 +41,14 @@ def self_update(): if current_content != response.text: with open(script_path, 'w', encoding='utf-8') as f: f.write(response.text) - logging.info("Script updated successfully, restarting") + logger.info("Script updated successfully, restarting") os.execv(sys.executable, ['python3'] + sys.argv) else: - logging.info("Script is up to date") + logger.info("Script is up to date") else: - logging.error(f"Failed to download update, status code: {response.status_code}") + logger.error(f"Failed to download update, status code: {response.status_code}") except Exception as e: - logging.error(f"Update error: {str(e)}") + logger.error(f"Update error: {str(e)}") class GRIST: def __init__(self, server, doc_id, api_key, logger): @@ -147,7 +148,7 @@ if __name__ == "__main__": logger.addHandler(ch) logger.info("Checker started") - self_update() + self_update(logger) random_sleep = random.randint(1, 60) logger.info(f"Sleeping for {random_sleep} seconds") time.sleep(random_sleep)