| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # | 2 # |
| 3 # Copyright 2013 The Chromium Authors. All rights reserved. | 3 # Copyright 2013 The Chromium Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Installs an APK. | 7 """Installs an APK. |
| 8 | 8 |
| 9 """ | 9 """ |
| 10 | 10 |
| 11 import optparse | 11 import optparse |
| 12 import os | 12 import os |
| 13 import re | 13 import re |
| 14 import subprocess |
| 14 import sys | 15 import sys |
| 15 | 16 |
| 16 # pylint: disable=F0401 | |
| 17 from util import build_device | 17 from util import build_device |
| 18 from util import build_utils | 18 from util import build_utils |
| 19 from util import md5_check | 19 from util import md5_check |
| 20 # pylint: enable=F0401 | |
| 21 | 20 |
| 22 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') | 21 BUILD_ANDROID_DIR = os.path.join(os.path.dirname(__file__), '..') |
| 23 sys.path.append(BUILD_ANDROID_DIR) | 22 sys.path.append(BUILD_ANDROID_DIR) |
| 24 | 23 |
| 25 from pylib import constants | 24 from pylib import constants |
| 26 from pylib.utils import apk_helper | 25 from pylib.utils import apk_helper |
| 27 | 26 |
| 28 def GetNewMetadata(device, apk_package): | 27 def GetNewMetadata(device, apk_package): |
| 29 """Gets the metadata on the device for the apk_package apk.""" | 28 """Gets the metadata on the device for the apk_package apk.""" |
| 30 output = device.RunShellCommand('ls -l /data/app/') | 29 output = device.RunShellCommand('ls -l /data/app/') |
| 31 # pylint: disable=C0301 | |
| 32 # Matches lines like: | 30 # Matches lines like: |
| 33 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t
estshell.apk | 31 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t
estshell.apk |
| 34 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t
estshell-1.apk | 32 # -rw-r--r-- system system 7376582 2013-04-19 16:34 org.chromium.chrome.t
estshell-1.apk |
| 35 # pylint: enable=C0301 | |
| 36 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) | 33 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?.apk$' % apk_package, s) |
| 37 matches = filter(apk_matcher, output) | 34 matches = filter(apk_matcher, output) |
| 38 return matches[0] if matches else None | 35 return matches[0] if matches else None |
| 39 | 36 |
| 40 def HasInstallMetadataChanged(device, apk_package, metadata_path): | 37 def HasInstallMetadataChanged(device, apk_package, metadata_path): |
| 41 """Checks if the metadata on the device for apk_package has changed.""" | 38 """Checks if the metadata on the device for apk_package has changed.""" |
| 42 if not os.path.exists(metadata_path): | 39 if not os.path.exists(metadata_path): |
| 43 return True | 40 return True |
| 44 | 41 |
| 45 with open(metadata_path, 'r') as expected_file: | 42 with open(metadata_path, 'r') as expected_file: |
| 46 return expected_file.read() != device.GetInstallMetadata(apk_package) | 43 return expected_file.read() != device.GetInstallMetadata(apk_package) |
| 47 | 44 |
| 48 | 45 |
| 49 def RecordInstallMetadata(device, apk_package, metadata_path): | 46 def RecordInstallMetadata(device, apk_package, metadata_path): |
| 50 """Records the metadata from the device for apk_package.""" | 47 """Records the metadata from the device for apk_package.""" |
| 51 metadata = GetNewMetadata(device, apk_package) | 48 metadata = GetNewMetadata(device, apk_package) |
| 52 if not metadata: | 49 if not metadata: |
| 53 raise Exception('APK install failed unexpectedly.') | 50 raise Exception('APK install failed unexpectedly.') |
| 54 | 51 |
| 55 with open(metadata_path, 'w') as outfile: | 52 with open(metadata_path, 'w') as outfile: |
| 56 outfile.write(metadata) | 53 outfile.write(metadata) |
| 57 | 54 |
| 58 | 55 |
| 59 def main(): | 56 def main(argv): |
| 60 parser = optparse.OptionParser() | 57 parser = optparse.OptionParser() |
| 61 parser.add_option('--apk-path', | 58 parser.add_option('--apk-path', |
| 62 help='Path to .apk to install.') | 59 help='Path to .apk to install.') |
| 63 parser.add_option('--install-record', | 60 parser.add_option('--install-record', |
| 64 help='Path to install record (touched only when APK is installed).') | 61 help='Path to install record (touched only when APK is installed).') |
| 65 parser.add_option('--build-device-configuration', | 62 parser.add_option('--build-device-configuration', |
| 66 help='Path to build device configuration.') | 63 help='Path to build device configuration.') |
| 67 parser.add_option('--stamp', | 64 parser.add_option('--stamp', |
| 68 help='Path to touch on success.') | 65 help='Path to touch on success.') |
| 69 parser.add_option('--configuration-name', | 66 parser.add_option('--configuration-name', |
| (...skipping 27 matching lines...) Expand all Loading... |
| 97 Install, | 94 Install, |
| 98 record_path=record_path, | 95 record_path=record_path, |
| 99 input_paths=[options.apk_path], | 96 input_paths=[options.apk_path], |
| 100 force=force_install) | 97 force=force_install) |
| 101 | 98 |
| 102 if options.stamp: | 99 if options.stamp: |
| 103 build_utils.Touch(options.stamp) | 100 build_utils.Touch(options.stamp) |
| 104 | 101 |
| 105 | 102 |
| 106 if __name__ == '__main__': | 103 if __name__ == '__main__': |
| 107 sys.exit(main()) | 104 sys.exit(main(sys.argv)) |
| OLD | NEW |