1- #!/usr/bin/python
2- #coding= utf-8
1+ #!/usr/bin/env python
2+ # -*- coding: utf-8 -*-
33
4- import os
5- import re
6- import platform
4+ '''
5+ Created on 2015年1月26日
76
8- #打开手机应用,运行脚本,会将该应用对应的apk复制到本地的Apps文件夹下
7+ @author: xuxu
8+ '''
99
10- PATH = lambda p : os . path . abspath ( p )
10+ import os
1111
12- system = platform .system ()
13- if system is "Windows" :
14- find_util = "findstr"
15- else :
16- find_util = "grep"
12+ from scriptUtils import utils
1713
18- def get_current_package_name ():
19- pattern = re .compile (r"[a-zA-Z0-9\.]+/.[a-zA-Z0-9\.]+" )
20- os .popen ("adb wait-for-device" )
21- out = os .popen ("adb shell dumpsys window w | %s \/ | %s name=" % (find_util , find_util )).read ()
22- package_name = pattern .findall (out )[0 ].split ("/" )[0 ]
14+ #打开手机上的第三方应用,运行脚本,会将该应用对应的apk复制到本地的App文件夹下
2315
24- return package_name
16+ PATH = lambda p : os . path . abspath ( p )
2517
2618def get_match_apk (package_name , path ):
2719 list = []
28- for packages in os . popen ( "adb shell pm list packages -f %s" % package_name ).readlines ():
20+ for packages in utils . shell ( " pm list packages -f %s" % package_name ). stdout .readlines ():
2921 list .append (packages .split (":" )[- 1 ].split ("=" )[0 ])
30- apk_name = list [0 ].split ("/" )[- 1 ]
31- os . popen ( "adb pull %s %s" % (list [0 ], path ))
22+ # apk_name = list[0].split("/")[-1]
23+ utils . adb ( " pull %s %s" % (list [0 ], path )). wait ( )
3224
3325if __name__ == "__main__" :
34- path = PATH (os .getcwd () + "/Apps" )
35- if not os .path .isdir (PATH (os .getcwd () + "/Apps" )):
26+ path = PATH ("%s/App" % os .getcwd ())
27+ if not os .path .isdir ("%s/App" % PATH (os .getcwd ())):
3628 os .makedirs (path )
3729
38- get_match_apk (get_current_package_name (), path )
30+ get_match_apk (utils .get_current_package_name (), path )
31+
0 commit comments