Last optimizations

This commit is contained in:
Jordan ERNST 2023-06-06 09:17:26 +02:00
parent de96fad7f7
commit f4fc03c26d
1 changed files with 31 additions and 8 deletions

View File

@ -1,3 +1,4 @@
from pathlib import Path
import requests import requests
import hashlib import hashlib
import sys import sys
@ -40,6 +41,15 @@ def yes_or_no(question, default=None):
print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n") print("Please respond with 'yes' or 'no' " "(or 'y' or 'n').\n")
def isAdbConnected():
cmdlist = ['adb', 'devices']
sp = subprocess.run(cmdlist, capture_output=True)
if len(sp.stdout.split(b'\n')) < 4:
return False
else:
return True
def isMagiskInstalled(): def isMagiskInstalled():
cmdlist = ['adb', 'shell', 'command', '-v', 'su'] cmdlist = ['adb', 'shell', 'command', '-v', 'su']
sp = subprocess.run(cmdlist, stdout=subprocess.DEVNULL, sp = subprocess.run(cmdlist, stdout=subprocess.DEVNULL,
@ -59,14 +69,20 @@ def checkInstalledVersion():
def downloadUpdate(device, version): def downloadUpdate(device, version):
filename = f"lineage-{version}.zip" filename = f"lineage-{version}.zip"
url = f'https://download.lineage.microg.org/{device}/{filename}'
r = requests.get(url, stream=True) if Path(filename).exists():
with tqdm.wrapattr(open(filename, "wb"), "write", print(f'{filename} already found locally.')
miniters=1, desc=filename, else:
total=int(r.headers.get('Content-Length'))) as fout: url = f'https://download.lineage.microg.org/{device}/{filename}'
for chunk in r.iter_content(chunk_size=4096): r = requests.get(url, stream=True)
fout.write(chunk) with tqdm.wrapattr(open(filename, "wb"),
fout.close() "write",
miniters=1,
desc=filename,
total=int(r.headers.get('Content-Length'))) as fout:
for chunk in r.iter_content(chunk_size=4096):
fout.write(chunk)
fout.close()
print('Comparing hashes...', end='', flush=True) print('Comparing hashes...', end='', flush=True)
checkHash(filename) checkHash(filename)
@ -150,6 +166,13 @@ def cleanUp(filename):
if __name__ == "__main__": if __name__ == "__main__":
print("Checking if an adb device is connected...", end='', flush=True)
if not isAdbConnected():
print("\nNo adb device is connected.")
print("Aborting.")
sys.exit()
print(' [OK]')
print("Checking if Magisk already installed...", end='', flush=True) print("Checking if Magisk already installed...", end='', flush=True)
if isMagiskInstalled(): if isMagiskInstalled():
print("\nIt seems Magisk is already installed (su in PATH).") print("\nIt seems Magisk is already installed (su in PATH).")