2424
2525# --------------------------------------------------------------------------------------------------------------------------
2626def 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+
4877def 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+
165224def 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
0 commit comments