diff --git a/main.py b/main.py index efed30d..8a322fa 100644 --- a/main.py +++ b/main.py @@ -1,31 +1,58 @@ from requests import get -import subprocess, os +import subprocess as sub +from datetime import datetime as dt, timezone as tz + +startTime = dt.now(tz.utc) +print(f"[INFO] Script started at {startTime.strftime('%Y-%m-%d %H:%M:%S.%f')}") oldVer = "" try: from localVersionCache import oldVer # pyright: ignore [reportMissingImports] + + print(f"[INFO] Old version is {oldVer}") except: - ... + print("[WARN] No old version found!") current = get( "https://api.github.com/repos/material-extensions/material-icons-browser-extension/releases/latest" ).json() -version = current["name"] +version = current["name"].lstrip( + "v" +) # Not sure if chrome extension versions can have a v? + +print(f"[INFO] Latest version is {version}") if version == oldVer: + endTime = dt.now(tz.utc) + print( + f"""[INFO] No updates available +[INFO] Script finished at {endTime.strftime('%Y-%m-%d %H:%M:%S.%f')} +[INFO] Execution time {endTime - startTime}""" + ) exit(0) -subprocess.run( +print( + """[INFO] Updating... +[INFO] Removing old files...""" +) + +sub.run( [ "rm", "-rf", "github-material-icons-chrome-extension", "github-material-icons-chrome-extension.zip", - ] + "github-material-icons-chrome-extension.crx", + "github-material-icons-chrome-extension.xml", + ], + stdout=sub.DEVNULL, + stderr=sub.DEVNULL, ) +print("[INFO] Downloading new .zip file...") + # Below is modifed from https://stackoverflow.com/a/16696317 file = get(current["assets"][0]["browser_download_url"], stream=True) @@ -34,13 +61,57 @@ with open("github-material-icons-chrome-extension.zip", "wb") as f: for chunk in file.iter_content(chunk_size=8192): f.write(chunk) -os.mkdir("github-material-icons-chrome-extension") +print("[INFO] Making directory to unzip to...") -subprocess.run( +sub.run( + [ + "mkdir", + "github-material-icons-chrome-extension", + ], + stdout=sub.DEVNULL, + stderr=sub.DEVNULL, +) + +print("[INFO] Unzipping...") + +sub.run( [ "unzip", "github-material-icons-chrome-extension.zip", "-d", "github-material-icons-chrome-extension", - ] + ], + stdout=sub.DEVNULL, + stderr=sub.DEVNULL, +) + +print("[INFO] Packing extension...") + +sub.run( + [ + "chromium", + "--pack-extension=github-material-icons-chrome-extension", + "--pack-extension-key=github-material-icons-chrome-extension.pem", + ], + stdout=sub.DEVNULL, + stderr=sub.DEVNULL, +) + +print("[INFO] Writing new XML file...") + +with open("github-material-icons-chrome-extension.xml", "w") as f: + f.writelines( + [ + '\n', + '\n', + f'\n', + "\n", + "", + ] + ) + +endTime = dt.now(tz.utc) +print( + f"""[INFO] Script finished at {endTime.strftime('%Y-%m-%d %H:%M:%S.%f')} +[INFO] Execution time {endTime - startTime}""" )