Exemplo n.º 1
0
def main():
  parser = argparse.ArgumentParser()
  parser.add_argument('build_path', help='Path to android build.')
  parser.add_argument(
      '-w', '--wipe', action='store_true', help='If set, wipes user data')
  logging_common.AddLoggingArguments(parser)
  script_common.AddDeviceArguments(parser)
  args = parser.parse_args()
  logging_common.InitializeLogging(args)

  if args.blacklist_file:
    blacklist = device_blacklist.Blacklist(args.blacklist_file).Read()
    if blacklist:
      logger.critical('Device(s) in blacklist, not flashing devices:')
      for key in blacklist:
        logger.critical('  %s', key)
      return exit_codes.INFRA

  flashed_devices = []
  failed_devices = []

  def flash(device):
    try:
      device.FlashDevice(args.build_path, wipe=args.wipe)
      flashed_devices.append(device)
    except Exception:  # pylint: disable=broad-except
      logger.exception('Device %s failed to flash.', str(device))
      failed_devices.append(device)

  devices = []
  try:
    adb_devices = script_common.GetDevices(args.devices, args.blacklist_file)
    devices += [fastboot_utils.FastbootUtils(device=d) for d in adb_devices]
  except device_errors.NoDevicesError:
    # Don't bail out if we're not looking for any particular device and there's
    # at least one sitting in fastboot mode. Note that if we ARE looking for a
    # particular device, and it's in fastboot mode, this will still fail.
    fastboot_devices = fastboot.Fastboot.Devices()
    if args.devices or not fastboot_devices:
      raise
    devices += [
        fastboot_utils.FastbootUtils(fastbooter=d) for d in fastboot_devices
    ]

  parallel_devices = parallelizer.SyncParallelizer(devices)
  parallel_devices.pMap(flash)

  if flashed_devices:
    logger.info('The following devices were flashed:')
    logger.info('  %s', ' '.join(str(d) for d in flashed_devices))
  if failed_devices:
    logger.critical('The following devices failed to flash:')
    logger.critical('  %s', ' '.join(str(d) for d in failed_devices))
    return exit_codes.INFRA
  return 0
Exemplo n.º 2
0
 def setUp(self):
   self.device_utils_mock = _DeviceUtilsMock(_SERIAL)
   self.fastboot_wrapper = _FastbootWrapperMock(_SERIAL)
   self.fastboot = fastboot_utils.FastbootUtils(
       self.device_utils_mock, fastbooter=self.fastboot_wrapper,
       default_timeout=2, default_retries=0)
   self.fastboot._board = _BOARD
 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)
Exemplo n.º 4
0
 def testInitWithMissing_fails(self):
   with self.assertRaises(ValueError):
     fastboot_utils.FastbootUtils(device=None, fastbooter=None)
   with self.assertRaises(AttributeError):
     fastboot_utils.FastbootUtils('abc')
Exemplo n.º 5
0
 def testInitWithDeviceUtil(self):
   f = fastboot_utils.FastbootUtils(self.device_utils_mock)
   self.assertEqual(str(self.device_utils_mock), str(f._device))
Exemplo n.º 6
0
 def testInitWithMissing_fails(self):
   with self.assertRaises(AttributeError):
     fastboot_utils.FastbootUtils(None)
   with self.assertRaises(AttributeError):
     fastboot_utils.FastbootUtils('')
  args = parser.parse_args()
  run_tests_helper.SetLogLevel(args.verbose)

  if args.blacklist_file:
    blacklist = device_blacklist.Blacklist(args.blacklist_file).Read()
    if blacklist:
      logger.critical('Device(s) in blacklist, not flashing devices:')
      for key in blacklist:
        logger.critical('  %s', key)
      return exit_codes.INFRA

  flashed_devices = []
  failed_devices = []

  def flash(presentation.device):
    fastboot = fastboot_utils.FastbootUtils(presentation.device)
    try:
      fastboot.FlashDevice(args.build_path, wipe=args.wipe)
      flashed_devices.append(presentation.device)
    except Exception:  # pylint: disable=broad-except
      logger.exception('Device %s failed to flash.', str(presentation.device))
      failed_devices.append(presentation.device)

  devices = script_common.GetDevices(args.devices, args.blacklist_file)
  device_utils.DeviceUtils.parallel(devices).pMap(flash)

  if flashed_devices:
    logger.info('The following devices were flashed:')
    logger.info('  %s', ' '.join(str(d) for d in flashed_devices))
  if failed_devices:
    logger.critical('The following devices failed to flash:')