-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutilities.py
78 lines (72 loc) · 2.97 KB
/
utilities.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from settings import *
import requests
import zipfile
import json
import subprocess
def getRealPath(oldpath):
real_path = os.path.realpath(oldpath)
return real_path
def downloadTSSChecker():
if PLATFORM == 'win32' or PLATFORM == 'win64':
name = '/tsschecker.exe'
dl_url = WIN_DOWN_LINK
elif PLATFORM == 'darwin':
name = '/tsschecker'
dl_url = MAC_DOWN_LINK
elif PLATFORM == 'linux' or PLATFORM == 'linux1' or PLATFORM == 'linux2':
name = '/tsschecker'
dl_url = LIN_DOWN_LINK
r = requests.get(dl_url, allow_redirects=True)
open(DOWN_DIR + '/tsschecker.zip', 'wb').write(r.content)
zip_ref = zipfile.ZipFile(DOWN_DIR + '/tsschecker.zip', 'r')
zip_ref.extractall(DOWN_DIR)
zip_ref.close()
os.remove(getRealPath(DOWN_DIR + '/tsschecker.zip'))
if PLATFORM == 'darwin' or PLATFORM == 'linux' or PLATFORM == 'linux1' or PLATFORM == 'linux2':
os.chmod(getRealPath(DOWN_DIR + name), 0o755)
def checkTSSChecker():
if PLATFORM == 'win32' or PLATFORM == 'win64':
name = '/tsschecker.exe'
elif PLATFORM == 'darwin' or PLATFORM == 'linux' or PLATFORM == 'linux1' or PLATFORM == 'linux2':
name = '/tsschecker'
if os.path.exists(getRealPath(DOWN_DIR + name)) == True:
return True
elif os.path.exists(getRealPath(DOWN_DIR + name)) == False:
try:
downloadTSSChecker()
return True
except:
return False
def checkConfig():
if os.path.exists(getRealPath(CUR_DIR + "/config/config.ini")) == False:
return False
else:
return True
def getSignedFirmwares(identifier):
headers = {'Accept':'application/json'}
api = "https://api.ipsw.me/v4/device/" + str(identifier) + "?type=ipsw"
print(api)
r = requests.get(str(api), headers=headers).text
obj = json.loads(r)
signed = ''
firmwares = obj['firmwares']
numOfFirmwares = len(obj['firmwares'])
for i in range(numOfFirmwares):
if obj['firmwares'][i]['signed'] == True:
if obj['firmwares'][i]['version'] not in signed:
signed += '\n' + obj['firmwares'][i]['version']
return signed
def saveBlobs(ecid, devId, boardconfig, version, latest):
if PLATFORM == 'win32' or PLATFORM == 'win64':
name = '/tsschecker.exe'
elif PLATFORM == 'darwin' or PLATFORM == 'linux' or PLATFORM == 'linux1' or PLATFORM == 'linux2':
name = '/tsschecker'
if version != '':
query = str(getRealPath(DOWN_DIR + name)) + ' ' + '-s ' + '-i ' + version + ' -e' + ecid + ' -d ' + devId + ' -B ' + ' ' + boardconfig
print(query)
elif version == '':
query = str(getRealPath(DOWN_DIR + name)) + ' -s ' + '-e ' + ecid + ' -d ' + devId + ' -B ' + boardconfig + ' ' + latest
print(query)
proc = subprocess.Popen(query, stdout=subprocess.PIPE, shell=True)
out = proc.communicate()[0]
return out.decode("utf-8")