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 """Runs semi-automated update testing on a non-rooted device.""" | 7 """Runs semi-automated update testing on a non-rooted device.""" |
8 import logging | 8 import logging |
9 import optparse | 9 import optparse |
10 import os | 10 import os |
11 import shutil | 11 import shutil |
12 import sys | 12 import sys |
13 import time | 13 import time |
14 | 14 |
15 from pylib import android_commands | 15 from pylib.device import adb_wrapper |
| 16 from pylib.device import device_filter |
16 from pylib.device import device_utils | 17 from pylib.device import device_utils |
17 | 18 |
18 def _SaveAppData(device, package_name, from_apk=None, data_dir=None): | 19 def _SaveAppData(device, package_name, from_apk=None, data_dir=None): |
19 def _BackupAppData(data_dir=None): | 20 def _BackupAppData(data_dir=None): |
20 device.adb.Backup(package_name) | 21 device.adb.Backup(package_name) |
21 backup_file = os.path.join(os.getcwd(), 'backup.ab') | 22 backup_file = os.path.join(os.getcwd(), 'backup.ab') |
22 assert os.path.exists(backup_file), 'Backup failed.' | 23 assert os.path.exists(backup_file), 'Backup failed.' |
23 if data_dir: | 24 if data_dir: |
24 if not os.path.isdir(data_dir): | 25 if not os.path.isdir(data_dir): |
25 os.makedirs(data_dir) | 26 os.makedirs(data_dir) |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 parser.add_option('--to-apk', help='APK to update to.') | 102 parser.add_option('--to-apk', help='APK to update to.') |
102 parser.add_option('--app-data', | 103 parser.add_option('--app-data', |
103 help=('Path to the application data to be restored or the ' | 104 help=('Path to the application data to be restored or the ' |
104 'directory where the data should be saved.')) | 105 'directory where the data should be saved.')) |
105 (options, args) = parser.parse_args() | 106 (options, args) = parser.parse_args() |
106 | 107 |
107 if args: | 108 if args: |
108 parser.print_help(sys.stderr) | 109 parser.print_help(sys.stderr) |
109 parser.error('Unknown arguments: %s.' % args) | 110 parser.error('Unknown arguments: %s.' % args) |
110 | 111 |
111 devices = android_commands.GetAttachedDevices() | 112 devices = adb_wrapper.AdbWrapper.Devices( |
| 113 filters=device_filter.DefaultFilters()) |
112 if len(devices) != 1: | 114 if len(devices) != 1: |
113 parser.error('Exactly 1 device must be attached.') | 115 parser.error('Exactly 1 device must be attached.') |
114 device = device_utils.DeviceUtils(devices[0]) | 116 device = device_utils.DeviceUtils(devices[0]) |
115 | 117 |
116 if options.from_apk: | 118 if options.from_apk: |
117 assert os.path.isfile(options.from_apk) | 119 assert os.path.isfile(options.from_apk) |
118 | 120 |
119 if options.save: | 121 if options.save: |
120 if not options.package_name: | 122 if not options.package_name: |
121 parser.print_help(sys.stderr) | 123 parser.print_help(sys.stderr) |
122 parser.error('Missing --package-name.') | 124 parser.error('Missing --package-name.') |
123 _SaveAppData(device, options.package_name, from_apk=options.from_apk, | 125 _SaveAppData(device, options.package_name, from_apk=options.from_apk, |
124 data_dir=options.app_data) | 126 data_dir=options.app_data) |
125 else: | 127 else: |
126 if not options.to_apk or not options.app_data: | 128 if not options.to_apk or not options.app_data: |
127 parser.print_help(sys.stderr) | 129 parser.print_help(sys.stderr) |
128 parser.error('Missing --to-apk or --app-data.') | 130 parser.error('Missing --to-apk or --app-data.') |
129 assert os.path.isfile(options.to_apk) | 131 assert os.path.isfile(options.to_apk) |
130 assert os.path.isfile(options.app_data) | 132 assert os.path.isfile(options.app_data) |
131 _VerifyAppUpdate(device, options.to_apk, options.app_data, | 133 _VerifyAppUpdate(device, options.to_apk, options.app_data, |
132 from_apk=options.from_apk) | 134 from_apk=options.from_apk) |
133 | 135 |
134 | 136 |
135 if __name__ == '__main__': | 137 if __name__ == '__main__': |
136 main() | 138 main() |
OLD | NEW |