forked from gb112211/AndroidTestScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_current_pkginfo.py
More file actions
46 lines (35 loc) · 1.34 KB
/
get_current_pkginfo.py
File metadata and controls
46 lines (35 loc) · 1.34 KB
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
#!/bin/env python
# -*- coding: utf-8 -*-
'''
Created on 2015年1月26日
@author: xuxu
'''
import os
import tempfile
from scriptUtils import utils
from scriptUtils.exception import SriptException
#获取设备上当前应用的包信息,结果存放于当前目录下的PackageInfo.txt中
PATH = lambda p: os.path.abspath(p)
tempFile = tempfile.gettempdir()
def get_aapt():
if "ANDROID_HOME" in os.environ:
rootDir = os.path.join(os.environ["ANDROID_HOME"], "build-tools")
for path, subdir, files in os.walk(rootDir):
if "aapt.exe" in files:
return os.path.join(path, "aapt.exe")
elif "aapt" in files:
return os.path.join(path, "aapt")
else:
raise SriptException("ANDROID_HOME not exist")
def get_match_apk(package_name):
list = []
for packages in utils.shell("pm list packages -f %s" %package_name).stdout.readlines():
list.append(packages.split(":")[-1].split("=")[0])
apk_name = list[0].split("/")[-1]
utils.adb("pull %s %s" %(list[0], tempFile)).wait()
return PATH("%s/%s" %(tempFile, apk_name))
if __name__ == "__main__":
package_name = utils.get_current_package_name()
os.popen("%s dump badging %s > PackageInfo.txt" %(get_aapt(), get_match_apk(package_name)))
# os.popen("del %s\\*.apk" %tempFile)
print "Completed"