OLD | NEW |
---|---|
(Empty) | |
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 """Gathers information about APKs.""" | |
6 | |
7 import logging | |
8 import os | |
9 import re | |
10 | |
11 from pylib import cmd_helper | |
craigdh
2013/01/04 02:00:32
add a TODO to move cmd_helper to utils/
frankf
2013/01/04 02:11:22
Done.
On 2013/01/04 02:00:32, craigdh wrote:
| |
12 | |
13 | |
14 def GetPackageNameForApk(apk_path): | |
15 """Returns the package name of this APK.""" | |
16 aapt_output = cmd_helper.GetCmdOutput( | |
17 ['aapt', 'dump', 'badging', apk_path]).split('\n') | |
18 package_name_re = re.compile(r'package: .*name=\'(\S*)\'') | |
19 for line in aapt_output: | |
20 m = package_name_re.match(line) | |
21 if m: | |
22 return m.group(1) | |
23 raise Exception('Failed to determine package name of %s' % apk_path) | |
24 | |
25 | |
26 class ApkInfo(object): | |
27 """Helper class for inspecting APKs.""" | |
28 | |
29 def __init__(self, apk_path): | |
30 if not os.path.exists(apk_path): | |
31 raise Exception('%s not found, please build it' % apk_path) | |
32 self._apk_path = apk_path | |
33 | |
34 def GetApkPath(self): | |
35 return self._apk_path | |
36 | |
37 def GetPackageName(self): | |
38 """Returns the package name of this APK.""" | |
39 return GetPackageNameForApk(self._apk_path) | |
40 | |
OLD | NEW |