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.
This commit is contained in:
parent
b93e5f890a
commit
b89e6c20ce
13
checker.py
13
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)
|
||||
|
Loading…
Reference in New Issue
Block a user