Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Unified Diff: build/android/devil/android/tools/flash_device.py

Issue 1412623009: [Android] Add CLI for flashing devices. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: move exit codes Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: build/android/devil/android/tools/flash_device.py
diff --git a/build/android/devil/android/tools/flash_device.py b/build/android/devil/android/tools/flash_device.py
new file mode 100755
index 0000000000000000000000000000000000000000..7289ddac39d9e95c00c731404b09732cda451a54
--- /dev/null
+++ b/build/android/devil/android/tools/flash_device.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python
+# Copyright 2015 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import argparse
+import logging
+import os
+import sys
+
+sys.path.append(os.path.join(os.path.dirname(os.path.abspath(__file__)),
jbudorick 2015/12/01 16:43:26 I don't think this shouldn't be necessary...
rnephew (Reviews Here) 2015/12/01 19:06:11 Done.
+ os.pardir, os.pardir, os.pardir))
+from devil.android import device_blacklist
+from devil.android import device_errors
+from devil.android import device_utils
+from devil.android import fastboot_utils
+from devil.android.sdk import adb_wrapper
+from devil.constants import exit_codes
+
+
+def GetDeviceList(device=None):
+ """Returns a list of devices.
+
+ If device is passed to it, returns only that device.
+ """
+ available_devices = [device_utils.DeviceUtils(d)
+ for d in adb_wrapper.AdbWrapper.GetDevices()]
jbudorick 2015/12/01 16:43:26 nit: one too many spaces after in
rnephew (Reviews Here) 2015/12/01 19:06:11 Done.
+ if not available_devices:
+ raise device_errors.NoDevicesError
+ if not device:
+ return available_devices
+ for d in available_devices:
+ if str(d) == device:
+ return [d]
+ raise device_errors.NoDevicesError
+
+
+def SetLoggingLevel(level):
jbudorick 2015/12/01 16:43:26 devil.utils.run_tests_helper.SetLogLevel I really
rnephew (Reviews Here) 2015/12/01 19:06:11 Done.
+ """Sets logging level."""
+ log_level = logging.WARNING
+ if level == 1:
+ log_level = logging.INFO
+ elif level >= 2:
+ log_level = logging.DEBUG
+ logging.basicConfig(level=log_level)
+
+
+def main():
+ parser = argparse.ArgumentParser()
+ parser.add_argument('build_path')
+ parser.add_argument('-d', '--device', help='Device to flash.')
+ parser.add_argument('-v', '--verbose', default=0, action='count',
+ help='Verbose level (multiple times for more)')
+ parser.add_argument('-w', '--wipe', action='store_true',
+ help='If set, wipes user data')
+ parser.add_argument('--blacklist-file', help='Device blacklist file.')
+ args = parser.parse_args()
+ SetLoggingLevel(args.verbose)
+
+ if args.blacklist_file:
+ blacklist = device_blacklist.Blacklist(args.blacklist_file).Read()
+ if blacklist:
+ logging.critical('Device(s) in blacklist, not flashing devices:')
+ for key in blacklist:
+ logging.critical(' %s', key)
+ return exit_codes.INFRA_EXIT_CODE
+
+ flashed_devices = []
+ failed_devices = []
+
+ def flash(device):
+ fastboot = fastboot_utils.FastbootUtils(device)
+ try:
+ fastboot.FlashDevice(args.build_path, wipe=args.wipe)
+ flashed_devices.append(device)
+ except Exception: # pylint: disable=broad-except
+ logging.exception('Device %s failed to flash.', str(device))
+ failed_devices.append(device)
+
+ devices = GetDeviceList(device=args.device)
+ device_utils.DeviceUtils.parallel(devices).pMap(flash)
+
+ if flashed_devices:
+ logging.info('The following devices were flashed:')
+ logging.info(' %s', ' '.join(str(d) for d in flashed_devices))
+ if failed_devices:
+ logging.critical('The following devices failed to flash:')
+ logging.critical(' %s', ' '.join(str(d) for d in failed_devices))
+ return exit_codes.INFRA_EXIT_CODE
+
jbudorick 2015/12/01 16:43:26 return 0
rnephew (Reviews Here) 2015/12/01 19:06:11 Done.
+if __name__ == '__main__':
+ sys.exit(main())
« no previous file with comments | « no previous file | build/android/devil/constants/__init__.py » ('j') | build/android/devil/constants/exit_codes.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698