Skip to content

Commit 01380e4

Browse files
author
chendianbo
committed
update to 1.3.0
1 parent 4b05c36 commit 01380e4

17 files changed

+525
-181
lines changed

basic/arguments.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def has(self, v):
3333
return False
3434

3535
def get(self, index, default=None):
36-
if 0 <= index < self.count(): return self.mKeys[index]
36+
if (0-self.count()) <= index < self.count(): return self.mKeys[index]
3737
return default
3838

3939
def getLast(self, index):
@@ -81,20 +81,22 @@ def __init__(self, argvs=None, help=[]):
8181
l = len(argvs)
8282
while i < l:
8383
k = argvs[i]
84-
if len(k) <= 1: continue
84+
if len(k) <= 1:
85+
i += 1
86+
continue
8587
if k.startswith('-'):
8688
if (i + 1) < l and not argvs[i + 1].startswith('-'):
8789
self.mKeys[k[1:]] = argvs[i + 1]
88-
i = i + 1
90+
i += 1
8991
else:
9092
self.mKeys[k[1:]] = ''
91-
i = i + 1
93+
i += 1
9294

9395
def has(self, k):
94-
return self.mKeys.has_key(k)
96+
return k in self.mKeys
9597

9698
def get(self, k):
97-
if self.mKeys.has_key(k): return self.mKeys[k]
99+
if k in self.mKeys: return self.mKeys[k]
98100
return None
99101

100102
def isEmpty(self):

extend/extend_adb.py

Lines changed: 76 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,22 @@
2424

2525
# --------------------------------------------------------------------------------------------------------------------------
2626
def doTopInfo():
27-
AdbUtils.dumpTop()
27+
topWinPackage, topActivityPackage = AdbUtils.dumpTop()
28+
LoggerUtils.light('Top window: ' + topWinPackage)
29+
LoggerUtils.light('Top activity: ' + topActivityPackage)
2830

2931

30-
def doPullPackage(projPath, pkg):
31-
if CmnUtils.isEmpty(pkg):
32-
LoggerUtils.error('Error: Invalid commands')
33-
LoggerUtils.println('The command is: "wing -adb pull {package name}"')
34-
return
32+
def doPullTop(projPath):
33+
LoggerUtils.light('do parse top app ...')
34+
topWinPackage, topActivityPackage = AdbUtils.dumpTop()
35+
if not CmnUtils.isEmpty(topWinPackage):
36+
LoggerUtils.light('do pull ' + topWinPackage + ' ...')
37+
doPullPackage(projPath, topWinPackage)
38+
if not CmnUtils.isEmpty(topActivityPackage) and topWinPackage != topActivityPackage:
39+
LoggerUtils.light('do pull ' + topActivityPackage + ' ...')
40+
doPullPackage(projPath, topActivityPackage)
3541

42+
def doPullPackage(projPath, pkg):
3643
pkgFile = AdbUtils.getApkFile(pkg)
3744
if CmnUtils.isEmpty(pkgFile):
3845
LoggerUtils.error('Error: ' + pkg + ' not found')
@@ -45,6 +52,28 @@ def doPullPackage(projPath, pkg):
4552
LoggerUtils.light(' to: ' + os.path.basename(outFile))
4653

4754

55+
def doPullPackages(projPath, name):
56+
if CmnUtils.isEmpty(name):
57+
LoggerUtils.error('Error: Invalid commands')
58+
LoggerUtils.println('The command is: "wing -adb pull [package name/all/file]"')
59+
return
60+
61+
if name == 'all':
62+
pkgs = AdbUtils.getInstallAppsWithThird()
63+
for pkg in pkgs:
64+
if CmnUtils.isEmpty(pkg): continue
65+
doPullPackage(projPath, pkg)
66+
elif os.path.isfile(name):
67+
with open(name, 'r') as f:
68+
lines = f.readlines()
69+
for line in lines:
70+
pkg = line.strip()
71+
if CmnUtils.isEmpty(pkg): continue
72+
doPullPackage(projPath, pkg)
73+
else:
74+
doPullPackage(projPath, name)
75+
76+
4877
def doStopApp(projPath, pkg):
4978
if not CmnUtils.isEmpty(pkg):
5079
AdbUtils.stop(pkg)
@@ -162,23 +191,61 @@ def doList():
162191
apps = AdbUtils.getInstallAppsWithDisable()
163192
doListPrint('Disabled', apps)
164193

194+
195+
def doDevice(help):
196+
AdbUtils.isDeviceConnected()
197+
LoggerUtils.println(AdbUtils.doAdbCmd('devices'))
198+
LoggerUtils.println(' ')
199+
LoggerUtils.println(' ')
200+
LoggerUtils.println('These are common adb commands used in wing:')
201+
LoggerUtils.println(help)
202+
203+
204+
def doUninstall(name):
205+
if name == 'all':
206+
apps = AdbUtils.getInstallAppsWithThird()
207+
for app in apps:
208+
if CmnUtils.isEmpty(app): continue
209+
AdbUtils.uninstall(app)
210+
LoggerUtils.println('uninstall: ' + app)
211+
elif os.path.isfile(name):
212+
with open(name, 'r') as f:
213+
lines = f.readlines()
214+
for line in lines:
215+
pkg = line.strip()
216+
if CmnUtils.isEmpty(pkg): continue
217+
AdbUtils.uninstall(pkg)
218+
LoggerUtils.println('uninstall: ' + pkg)
219+
else:
220+
AdbUtils.uninstall(name)
221+
LoggerUtils.println('uninstall: ' + name)
222+
223+
165224
def run():
166-
"""
225+
help = """
167226
wing -adb top
168227
wing -adb list
169-
wing -adb pull <package name>
228+
wing -adb pull [package name/all/file]
170229
wing -adb stop <package name>
171230
wing -adb clear <package name>
172231
wing -adb dump [ui/sys/log]
232+
wing -adb uninstall [package name/all/file]
173233
"""
234+
174235
za = BasicArgumentsValue()
175236
envPath, spacePath, typ = za.get(0), za.get(1), za.get(2)
237+
if CmnUtils.isEmpty(typ): return doDevice(help)
176238
if typ == 'top': return doTopInfo()
177-
if typ == 'pull': return doPullPackage(envPath, za.get(3))
239+
if typ == 'pull':
240+
pkg = za.get(3)
241+
if 'top' == pkg:
242+
return doPullTop(envPath)
243+
return doPullPackage(envPath, pkg)
178244
if typ == 'stop': return doStopApp(envPath, za.get(3))
179245
if typ == 'clear': return doClearApp(envPath, za.get(3))
180246
if typ == 'dump': return doDump(envPath, za.get(3))
181247
if typ == 'list': return doList()
248+
if typ == 'uninstall': return doUninstall(za.get(3))
182249
assert 0, 'Unsupported type: ' + typ
183250

184251

extend/extend_build.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
# --------------------------------------------------------------------------------------------------------------------------
2121
def doBuild(spacePath, projName, projPath, buildType, subModule):
22+
if os.path.isfile(spacePath + "/build.py"):
23+
succ = CmnUtils.doCmdCall('cd %s && python build.py %s pre-build' % (spacePath, buildType))
24+
assert succ, 'pre build fail'
25+
2226
outPath = '%s/out/%s' % (spacePath, projName)
2327
try:
2428
os.makedirs(outPath)
@@ -82,7 +86,9 @@ def run():
8286
# eg: wing -build [$sub_module], such as:
8387
# wing -build
8488
# wing -build jni
85-
doBuild(spacePath, projName, projPath, 'all', subModule)
89+
# doBuild(spacePath, projName, projPath, 'all', subModule)
90+
doBuild(spacePath, projName, projPath, 'debug', subModule)
91+
doBuild(spacePath, projName, projPath, 'release', subModule)
8692

8793

8894
if __name__ == "__main__":

extend/extend_key.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@ def doHash(str):
110110
LoggerUtils.println('{ 0x%x, 0x%x }, // %s' % (h, f, str))
111111

112112

113+
def showHelp():
114+
help = '''
115+
-key {type}
116+
create {key type} {mode}
117+
create RSA public and private keys with 1024 or 2048(default) mode
118+
list {file} [pwd]
119+
print key/sign information for apk/ipa/mobileprovision/keystore/jks/rsa/... file
120+
hash {string}
121+
print md5/sha256/hash/... of string
122+
'''
123+
LoggerUtils.println(' ')
124+
LoggerUtils.println(help)
125+
126+
113127
def run():
114128
'''
115129
wing -key
@@ -123,7 +137,8 @@ def run():
123137
if cmd == 'create': return doCreate(envPath, argv.get(3), argv.get(4))
124138
# "wing -key hash ${string}"
125139
if cmd == 'hash': return doHash(argv.get(3))
126-
LoggerUtils.error('Unsupported command: ' + cmd)
140+
141+
showHelp();
127142

128143

129144
if __name__ == "__main__":

extend/extend_plugin.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
# @brief: third plugin
4+
# @date: 2024.05.10 14:40:50
5+
6+
import os
7+
import shutil
8+
import sys
9+
10+
g_this_file = os.path.realpath(sys.argv[0])
11+
g_this_path = os.path.dirname(g_this_file)
12+
sys.path.append(os.path.dirname(g_this_path))
13+
14+
from utils.utils_cmn import CmnUtils
15+
from utils.utils_cmn import CmnVersion
16+
from utils.utils_logger import LoggerUtils
17+
from utils.utils_import import ImportUtils
18+
from utils.utils_zip import ZipUtils
19+
from utils.utils_net import NetUtils
20+
from utils.utils_file import FileUtils
21+
from basic.arguments import BasicArgumentsValue
22+
23+
g_wing_path = ImportUtils.initEnv(os.path.dirname(g_this_path))
24+
25+
#
26+
# server files:
27+
#
28+
# local path:
29+
# ${wing root path}/plugin/${plugin name}/*
30+
# ${wing root path}/plugin/${plugin name}/${plugin name}.ver
31+
#
32+
33+
# --------------------------------------------------------------------------------------------------------------------------
34+
35+
def run():
36+
"""
37+
wing -apktool $@
38+
wing -jadx $@
39+
"""
40+
za = BasicArgumentsValue()
41+
envPath, spacePath, name = za.get(0), za.get(1), za.get(2)
42+
if name == '-jadx':
43+
pluginPath = os.path.dirname(g_wing_path) + '/plugin/jadx'
44+
if not os.path.isfile(pluginPath + '/jadx.ver'):
45+
LoggerUtils.e('\tjadx not install, run \"wing -update\"')
46+
return
47+
CmnUtils.doCmdCall(pluginPath + '/bin/jadx-gui&')
48+
return
49+
if name == '-apktool':
50+
pluginPath = os.path.dirname(g_wing_path) + '/plugin/apktool'
51+
if not os.path.isfile(pluginPath + '/apktool.ver'):
52+
LoggerUtils.e('\tapktool not install, run \"wing -update\"')
53+
return
54+
CmnUtils.doCmdCall('cd ' + envPath + ' && java -jar ' + pluginPath + '/apktool.jar ' + ' '.join(za.getLast(3)))
55+
return
56+
assert 0, 'Unsupported type: ' + name
57+
58+
59+
if __name__ == "__main__":
60+
run()
61+

extend/extend_screen.py

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,40 @@
2323

2424
BASE_URL_FMT = 'http://www.iofomo.com/download/scrcpy/scrcpy-%s'
2525
# --------------------------------------------------------------------------------------------------------------------------
26-
def doScreen():
26+
def doEnvPrepare():
2727
AdbUtils.ensureEnv()
2828
sysEnv = isEnvOK()
2929
if not sysEnv:
3030
binFile = getBinFile()
31-
if None == binFile: return
31+
return sysEnv, binFile
32+
return sysEnv, None
3233

33-
dd = AdbUtils.getDevices()
34-
# print(dd)
35-
if CmnUtils.isEmpty(dd):
34+
35+
def doLaunchDevice(sysEnv, binFile, did):
36+
LoggerUtils.println('Launch device: ' + did)
37+
if sysEnv:
38+
CmnUtils.doCmd("scrcpy -s " + did + " &")
39+
elif binFile is not None:
40+
CmnUtils.doCmd('%s -s %s &' % (CmnUtils.formatCmdArg(binFile), did))
41+
else:
42+
LoggerUtils.e('scrcpy not found')
43+
44+
45+
def doScreen(dids):
46+
sysEnv, binFile = doEnvPrepare()
47+
if CmnUtils.isEmpty(dids):
48+
dids = AdbUtils.getDevices()
49+
# print(dids)
50+
if CmnUtils.isEmpty(dids):
3651
LoggerUtils.e('No devices found')
3752
return
38-
if sysEnv:
39-
for d in dd: CmnUtils.doCmd("scrcpy -s " + d + " &")
53+
if sysEnv is None and binFile is None:
54+
LoggerUtils.e('scrcpy not found')
4055
return
4156

42-
if binFile is None: return
43-
for d in dd: CmnUtils.doCmd('%s -s %s &' % (CmnUtils.formatCmdArg(binFile), d))
57+
for did in dids:
58+
doLaunchDevice(sysEnv, binFile, did)
59+
4460

4561
def isEnvOK():
4662
ret = CmnUtils.doCmd("scrcpy -v")
@@ -81,12 +97,12 @@ def getBinFile():
8197

8298
def run():
8399
"""
84-
wing -screen
100+
wing -screen [device id]
85101
"""
86102
za = BasicArgumentsValue()
87-
envPath, spacePath, typ = za.get(0), za.get(1), za.get(2)
88-
if typ is None: return doScreen()
89-
assert 0, 'Unsupported type: ' + typ
103+
envPath, spacePath = za.get(0), za.get(1)
104+
return doScreen(za.getLast(2))
105+
# assert 0, 'Unsupported type: ' + typ
90106

91107

92108
if __name__ == "__main__":

extend/extend_test.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python
2+
# -*- coding:utf-8 -*-
3+
# @brief: Mobile device test commands
4+
# @date: 2024.02.10 14:40:50
5+
6+
import os
7+
import shutil
8+
import sys
9+
10+
g_this_file = os.path.realpath(sys.argv[0])
11+
g_this_path = os.path.dirname(g_this_file)
12+
sys.path.append(os.path.dirname(g_this_path))
13+
14+
from utils.utils_cmn import CmnUtils
15+
from utils.utils_logger import LoggerUtils
16+
from utils.utils_import import ImportUtils
17+
from utils.utils_file import FileUtils
18+
from basic.arguments import BasicArgumentsValue
19+
20+
g_wing_path = ImportUtils.initEnv(os.path.dirname(g_this_path))
21+
22+
# --------------------------------------------------------------------------------------------------------------------------
23+
def doTest(path, envPath, spacePath, argv):
24+
succ = CmnUtils.doCmdCall('cd "%s" && python test.py "%s" "%s" %s' % (path, envPath, spacePath, CmnUtils.joinArgs(argv)))
25+
assert succ, 'test run fail'
26+
27+
28+
def run():
29+
"""
30+
wing -test <cmds>
31+
"""
32+
za = BasicArgumentsValue()
33+
envPath, spacePath, argv = za.get(0), za.get(1), za.getLast(2)
34+
if os.path.isfile(envPath + "/test.py"):
35+
doTest(envPath, envPath, spacePath, argv)
36+
elif os.path.isfile(spacePath + "/test.py"):
37+
doTest(spacePath, envPath, spacePath, argv)
38+
else:
39+
LoggerUtils.e('No test.py found !')
40+
41+
42+
if __name__ == "__main__":
43+
run()

0 commit comments

Comments
 (0)