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 # TODO(frankf): Move cmd_helper to utils. |
| 12 from pylib import cmd_helper |
| 13 |
| 14 |
| 15 def GetPackageNameForApk(apk_path): |
| 16 """Returns the package name of this APK.""" |
| 17 aapt_output = cmd_helper.GetCmdOutput( |
| 18 ['aapt', 'dump', 'badging', apk_path]).split('\n') |
| 19 package_name_re = re.compile(r'package: .*name=\'(\S*)\'') |
| 20 for line in aapt_output: |
| 21 m = package_name_re.match(line) |
| 22 if m: |
| 23 return m.group(1) |
| 24 raise Exception('Failed to determine package name of %s' % apk_path) |
| 25 |
| 26 |
| 27 class ApkInfo(object): |
| 28 """Helper class for inspecting APKs.""" |
| 29 |
| 30 def __init__(self, apk_path): |
| 31 if not os.path.exists(apk_path): |
| 32 raise Exception('%s not found, please build it' % apk_path) |
| 33 self._apk_path = apk_path |
| 34 |
| 35 def GetApkPath(self): |
| 36 return self._apk_path |
| 37 |
| 38 def GetPackageName(self): |
| 39 """Returns the package name of this APK.""" |
| 40 return GetPackageNameForApk(self._apk_path) |
| 41 |
OLD | NEW |