forked from kefir500/apk-editor-studio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownload.py
85 lines (69 loc) · 3.1 KB
/
download.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
79
80
81
82
83
84
85
#!/usr/bin/env python3
import os
import sys
from urllib.request import urlretrieve
from zipfile import ZipFile
def unzip(z, src, dst, binary=False):
dst = os.path.join(dst, os.path.basename(src))
with open(dst, 'wb') as f:
f.write(z.read(src))
if binary and sys.platform != 'win32':
os.chmod(dst, 0o755)
def resolveExecutableName(path):
return path if sys.platform != 'win32' else path + '.exe'
def resolvePath(path):
return os.path.join(os.path.dirname(__file__), path)
def resolvePlatformPath():
path = resolvePath('../dist')
if sys.platform == 'win32':
return os.path.join(path, 'windows/tools')
elif sys.platform == 'linux':
return os.path.join(path, 'linux/bin')
elif sys.platform == 'darwin':
return os.path.join(path, 'macos/app/Contents/MacOS')
def progress(blocknum, blocksize, totalsize):
bytesdone = min(blocknum * blocksize, totalsize)
percent = bytesdone * 1e2 / totalsize
s = '\r%5.1f%% %*d / %d KB' % (percent, len(str(totalsize)), bytesdone / 1024, totalsize / 1024)
sys.stderr.write(s)
if bytesdone >= totalsize:
sys.stderr.write('\n')
# Prepare
os.makedirs(resolvePath('../dist/all/tools'), exist_ok=True)
os.makedirs(resolvePlatformPath(), exist_ok=True)
# Download Apktool
print('(1/3) Downloading Apktool...')
urlretrieve('https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.7.0.jar',
resolvePath('../dist/all/tools/apktool.jar'), progress)
# Download and unpack Android Build Tools
print('(2/3) Downloading Android Build Tools...')
buildToolsUrl = 'https://dl.google.com/android/repository/build-tools_r33.0.1-{}.zip'
if sys.platform == 'win32':
buildToolsUrl = buildToolsUrl.format('windows')
elif sys.platform == 'linux':
buildToolsUrl = buildToolsUrl.format('linux')
elif sys.platform == 'darwin':
buildToolsUrl = buildToolsUrl.format('macosx')
urlretrieve(buildToolsUrl, 'build-tools.zip', progress)
with ZipFile('build-tools.zip') as z:
unzip(z, 'android-13/lib/apksigner.jar', resolvePath('../dist/all/tools/'))
unzip(z, resolveExecutableName('android-13/zipalign'), resolvePlatformPath(), True)
if sys.platform == 'win32':
unzip(z, 'android-13/libwinpthread-1.dll', resolvePlatformPath())
os.remove('build-tools.zip')
# Download and unpack Android SDK Platform Tools
print('(3/3) Downloading Android SDK Platform Tools...')
platformToolsUrl = 'https://dl.google.com/android/repository/platform-tools-latest-{}.zip'
if sys.platform == 'win32':
platformToolsUrl = platformToolsUrl.format('windows')
elif sys.platform == 'linux':
platformToolsUrl = platformToolsUrl.format('linux')
elif sys.platform == 'darwin':
platformToolsUrl = platformToolsUrl.format('darwin')
urlretrieve(platformToolsUrl, 'platform-tools.zip', progress)
with ZipFile('platform-tools.zip') as z:
unzip(z, resolveExecutableName('platform-tools/adb'), resolvePlatformPath(), True)
if sys.platform == 'win32':
unzip(z, 'platform-tools/AdbWinApi.dll', resolvePlatformPath())
unzip(z, 'platform-tools/AdbWinUsbApi.dll', resolvePlatformPath())
os.remove('platform-tools.zip')