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 | |
14 import sys | 13 import sys |
15 | 14 |
16 from util import build_device | 15 from util import build_device |
17 from util import build_utils | 16 from util import build_utils |
18 from util import md5_check | 17 from util import md5_check |
19 | 18 |
20 BUILD_ANDROID_DIR = os.path.abspath( | 19 BUILD_ANDROID_DIR = os.path.abspath( |
21 os.path.join(os.path.dirname(__file__), '..')) | 20 os.path.join(os.path.dirname(__file__), '..')) |
22 sys.path.append(BUILD_ANDROID_DIR) | 21 sys.path.append(BUILD_ANDROID_DIR) |
23 | 22 |
24 import devil_chromium | 23 import devil_chromium |
25 from devil.android import apk_helper | 24 from devil.android import apk_helper |
26 from pylib import constants | 25 from pylib import constants |
27 | 26 |
28 | 27 |
29 def GetNewMetadata(device, apk_package): | |
30 """Gets the metadata on the device for the apk_package apk.""" | |
31 output = device.RunShellCommand('ls -l /data/app/') | |
32 # Matches lines like: | |
33 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ | |
34 # org.chromium.chrome.apk | |
35 # -rw-r--r-- system system 7376582 2013-04-19 16:34 \ | |
36 # org.chromium.chrome-1.apk | |
37 apk_matcher = lambda s: re.match('.*%s(-[0-9]*)?(.apk)?$' % apk_package, s) | |
38 matches = filter(apk_matcher, output) | |
39 return matches[0] if matches else None | |
perezju
2016/06/15 14:54:45
Replaced below with device.GetInstallMetadata(apk_
| |
40 | |
41 def HasInstallMetadataChanged(device, apk_package, metadata_path): | 28 def HasInstallMetadataChanged(device, apk_package, metadata_path): |
42 """Checks if the metadata on the device for apk_package has changed.""" | 29 """Checks if the metadata on the device for apk_package has changed.""" |
43 if not os.path.exists(metadata_path): | 30 if not os.path.exists(metadata_path): |
44 return True | 31 return True |
45 | 32 |
46 with open(metadata_path, 'r') as expected_file: | 33 try: |
47 return expected_file.read() != device.GetInstallMetadata(apk_package) | 34 expected_metadata = build_utils.ReadJson(metadata_path) |
35 except ValueError: # File is not json encoded. | |
36 return True | |
perezju
2016/06/15 14:54:45
Give some tolerance for old files (with the output
agrieve
2016/06/15 17:25:24
One step even better would be to change this file
perezju
2016/06/16 09:31:28
Had a quick look, but the change would be a bit mo
| |
37 | |
38 return expected_metadata != device.GetInstallMetadata(apk_package) | |
48 | 39 |
49 | 40 |
50 def RecordInstallMetadata(device, apk_package, metadata_path): | 41 def RecordInstallMetadata(device, apk_package, metadata_path): |
51 """Records the metadata from the device for apk_package.""" | 42 """Records the metadata from the device for apk_package.""" |
52 metadata = GetNewMetadata(device, apk_package) | 43 metadata = device.GetInstallMetadata(apk_package, refresh=True) |
53 if not metadata: | 44 if not metadata: |
54 raise Exception('APK install failed unexpectedly.') | 45 raise Exception('APK install failed unexpectedly.') |
55 | 46 |
56 with open(metadata_path, 'w') as outfile: | 47 build_utils.WriteJson(metadata, metadata_path) |
57 outfile.write(metadata) | |
58 | 48 |
59 | 49 |
60 def main(): | 50 def main(): |
61 parser = optparse.OptionParser() | 51 parser = optparse.OptionParser() |
62 parser.add_option('--apk-path', | 52 parser.add_option('--apk-path', |
63 help='Path to .apk to install.') | 53 help='Path to .apk to install.') |
64 parser.add_option('--split-apk-path', | 54 parser.add_option('--split-apk-path', |
65 help='Path to .apk splits (can specify multiple times, causes ' | 55 help='Path to .apk splits (can specify multiple times, causes ' |
66 '--install-multiple to be used.', | 56 '--install-multiple to be used.', |
67 action='append') | 57 action='append') |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 record_path=record_path, | 106 record_path=record_path, |
117 input_paths=[options.apk_path], | 107 input_paths=[options.apk_path], |
118 force=force_install) | 108 force=force_install) |
119 | 109 |
120 if options.stamp: | 110 if options.stamp: |
121 build_utils.Touch(options.stamp) | 111 build_utils.Touch(options.stamp) |
122 | 112 |
123 | 113 |
124 if __name__ == '__main__': | 114 if __name__ == '__main__': |
125 sys.exit(main()) | 115 sys.exit(main()) |
OLD | NEW |