-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtinker-patch.py
74 lines (63 loc) · 2.06 KB
/
tinker-patch.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
#!/usr/bin/python
# coding: utf8
import sys, os
import subprocess
import getopt
import platform
multi_apk_dir = ''
new_apk = ''
def get_prop(argv):
try:
opts, args = getopt.getopt(argv, "hd:n:", ["multiApkDir=", "newApk="])
except getopt.GetoptError:
print('tinker-patch.py -d <multiApkDir> -n <newApk>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('tinker-patch.py -d <multiApkDir> -n <newApk>')
sys.exit()
elif opt in ("-d", "--multiApkDir"):
global multi_apk_dir
multi_apk_dir = arg
elif opt in ("-n", "--newApk"):
global new_apk
new_apk = arg
return
def release_patch(old_path):
if platform.system() == "Windows":
cmd_head = "gradlew.bat -Pcommand"
else:
cmd_head = "./gradlew -Pcommand"
if new_apk == '':
patch_cmd = cmd_head + ' app:initDir -PmultiApkDir=' + old_path + ' app:buildTinkerPatchRelease' # --info
else:
patch_cmd = cmd_head + ' app:initDir -PmultiApkDir=' + old_path + ' -PnewApkPath=' + new_apk + ' app:buildTinkerPatchRelease' # --info
print("patch_cmd: "+patch_cmd)
p = subprocess.Popen(patch_cmd, shell=(platform.system() != "Windows"), stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
while p.poll() is None:
line = p.stdout.readline()
line = line.strip()
if line:
print(line)
if p.returncode == 0:
print('Subprogram success')
else:
print('Subprogram failed')
return
# 用于匹配文件
def fetch_file():
print('multiApkDir: ' + multi_apk_dir)
g = os.listdir(r"" + multi_apk_dir + "")
for base_name in g:
apk = os.path.join(multi_apk_dir, base_name)
if not os.path.isdir(apk): continue
if base_name == 'patch': continue
print('base_name:==>' + base_name)
print('new_apk:==>' + new_apk)
# 制作补丁包
release_patch(apk)
return
if __name__ == "__main__":
get_prop(sys.argv[1:])
fetch_file()