示例#1
0
def GetSerial(device_type):
  """ Determine the serial number of the *first* connected device with the
  specified type.  The ordering of 'adb devices' is not documented, and the
  connected devices do not appear to be ordered by serial number.  Therefore,
  we have to assume that, in the case of multiple devices of the same type being
  connected to one host, we cannot predict which device will be chosen.

  device_type: string indicating the 'common name' for the target device
  """
  if not device_type in DEVICE_LOOKUP:
    raise ValueError('Unknown device: %s!' % device_type)
  device_name = DEVICE_LOOKUP[device_type]
  output = shell_utils.run_retry('%s devices' % PATH_TO_ADB, shell=True,
                                 attempts=5)
  print output
  lines = output.split('\n')
  device_ids = []
  for line in lines:
    # Filter garbage lines
    if line != '' and not ('List of devices attached' in line) and \
        line[0] != '*':
      device_ids.append(line.split('\t')[0])
  for device_id in device_ids:
    print 'Finding type for id %s' % device_id
    # Get device name
    name_line = shell_utils.run_retry(
        '%s -s %s shell cat /system/build.prop | grep "ro.product.device="' % (
            PATH_TO_ADB, device_id), shell=True, attempts=5)
    print name_line
    name = name_line.split('=')[-1].rstrip()
    # Just return the first attached device of the requested model.
    if device_name in name:
      return device_id
  raise Exception('No %s device attached!' % device_name)
示例#2
0
def Sync(revisions=None, force=False, delete_unversioned_trees=False,
         verbose=False, jobs=None, no_hooks=False, extra_args=None):
  """ Update the local checkout using gclient.

  Args:
      revisions: optional list of (branch, revision) tuples indicating which
          projects to sync to which revisions.
      force: whether to run with --force.
      delete_unversioned_trees: whether to run with --delete-unversioned-trees.
      verbose: whether to run with --verbose.
      jobs: optional argument for the --jobs flag.
      no_hooks: whether to run with --nohooks.
      extra_args: optional list; any additional arguments.
  """
  for branch, _ in (revisions or []):
    # Do whatever it takes to get up-to-date with origin/master.
    if os.path.exists(branch):
      with misc.ChDir(branch):
        # First, fix the git identity if needed.
        maybe_fix_identity()

        # If there are local changes, "git checkout" will fail.
        shell_utils.run([GIT, 'reset', '--hard', 'HEAD'])
        # In case HEAD is detached...
        shell_utils.run([GIT, 'checkout', 'master'])
        # Always fetch, in case we're unmanaged.
        shell_utils.run_retry([GIT, 'fetch'], attempts=5)
        # This updates us to origin/master even if master has diverged.
        shell_utils.run([GIT, 'reset', '--hard', 'origin/master'])

  cmd = ['sync', '--no-nag-max']
  if verbose:
    cmd.append('--verbose')
  if force:
    cmd.append('--force')
  if delete_unversioned_trees:
    cmd.append('--delete_unversioned_trees')
  if jobs:
    cmd.append('-j%d' % jobs)
  if no_hooks:
    cmd.append('--nohooks')
  for branch, revision in (revisions or []):
    if revision:
      cmd.extend(['--revision', '%s@%s' % (branch, revision)])
  if extra_args:
    cmd.extend(extra_args)
  output = _RunCmd(cmd)

  # "gclient sync" just downloads all of the commits. In order to actually sync
  # to the desired commit, we have to "git reset" to that commit.
  for branch, revision in (revisions or []):
    with misc.ChDir(branch):
      if revision:
        shell_utils.run([GIT, 'reset', '--hard', revision])
      else:
        shell_utils.run([GIT, 'reset', '--hard', 'origin/master'])
  return output
示例#3
0
def RunADB(serial, cmd, echo=True, attempts=5, secs_between_attempts=10,
           timeout=None):
  """ Run 'cmd' on an Android device, using ADB.  No return value; throws an
  exception if the command fails more than the allotted number of attempts.

  serial: string indicating the serial number of the target device
  cmd: string; the command to issue on the device
  attempts: number of times to attempt the command
  secs_between_attempts: number of seconds to wait between attempts
  timeout: optional, integer indicating the maximum elapsed time in seconds
  """
  adb_cmd = [PATH_TO_ADB, '-s', serial]
  adb_cmd += cmd
  shell_utils.run_retry(adb_cmd, echo=echo, attempts=attempts,
                        secs_between_attempts=secs_between_attempts)
示例#4
0
def RunADB(serial,
           cmd,
           echo=True,
           attempts=5,
           secs_between_attempts=10,
           timeout=None):
    """ Run 'cmd' on an Android device, using ADB.  No return value; throws an
  exception if the command fails more than the allotted number of attempts.

  serial: string indicating the serial number of the target device
  cmd: string; the command to issue on the device
  attempts: number of times to attempt the command
  secs_between_attempts: number of seconds to wait between attempts
  timeout: optional, integer indicating the maximum elapsed time in seconds
  """
    adb_cmd = [PATH_TO_ADB, '-s', serial]
    adb_cmd += cmd
    shell_utils.run_retry(adb_cmd,
                          echo=echo,
                          attempts=attempts,
                          secs_between_attempts=secs_between_attempts)
示例#5
0
def GetSerial(device_type):
    """ Determine the serial number of the *first* connected device with the
  specified type.  The ordering of 'adb devices' is not documented, and the
  connected devices do not appear to be ordered by serial number.  Therefore,
  we have to assume that, in the case of multiple devices of the same type being
  connected to one host, we cannot predict which device will be chosen.

  device_type: string indicating the 'common name' for the target device
  """
    if not device_type in DEVICE_LOOKUP:
        raise ValueError('Unknown device: %s!' % device_type)
    device_name = DEVICE_LOOKUP[device_type]
    output = shell_utils.run_retry('%s devices' % PATH_TO_ADB,
                                   shell=True,
                                   attempts=5)
    print output
    lines = output.split('\n')
    device_ids = []
    for line in lines:
        # Filter garbage lines
        if line != '' and not ('List of devices attached' in line) and \
            line[0] != '*':
            device_ids.append(line.split('\t')[0])
    for device_id in device_ids:
        print 'Finding type for id %s' % device_id
        # Get device name
        name_line = shell_utils.run_retry(
            '%s -s %s shell cat /system/build.prop | grep "ro.product.device="'
            % (PATH_TO_ADB, device_id),
            shell=True,
            attempts=5)
        print name_line
        name = name_line.split('=')[-1].rstrip()
        # Just return the first attached device of the requested model.
        if device_name in name:
            return device_id
    raise Exception('No %s device attached!' % device_name)
def Sync(revisions=None,
         force=False,
         delete_unversioned_trees=False,
         verbose=False,
         jobs=None,
         no_hooks=False,
         extra_args=None):
    """ Update the local checkout using gclient.

  Args:
      revisions: optional list of (branch, revision) tuples indicating which
          projects to sync to which revisions.
      force: whether to run with --force.
      delete_unversioned_trees: whether to run with --delete-unversioned-trees.
      verbose: whether to run with --verbose.
      jobs: optional argument for the --jobs flag.
      no_hooks: whether to run with --nohooks.
      extra_args: optional list; any additional arguments.
  """
    for branch, _ in (revisions or []):
        # Do whatever it takes to get up-to-date with origin/master.
        if os.path.exists(branch):
            with misc.ChDir(branch):
                # First, fix the git identity if needed.
                maybe_fix_identity()

                # If there are local changes, "git checkout" will fail.
                shell_utils.run([GIT, 'reset', '--hard', 'HEAD'])
                # In case HEAD is detached...
                shell_utils.run([GIT, 'checkout', 'master'])
                # Always fetch, in case we're unmanaged.
                shell_utils.run_retry([GIT, 'fetch'], attempts=5)
                # This updates us to origin/master even if master has diverged.
                shell_utils.run([GIT, 'reset', '--hard', 'origin/master'])

    cmd = ['sync', '--no-nag-max']
    if verbose:
        cmd.append('--verbose')
    if force:
        cmd.append('--force')
    if delete_unversioned_trees:
        cmd.append('--delete_unversioned_trees')
    if jobs:
        cmd.append('-j%d' % jobs)
    if no_hooks:
        cmd.append('--nohooks')
    for branch, revision in (revisions or []):
        if revision:
            cmd.extend(['--revision', '%s@%s' % (branch, revision)])
    if extra_args:
        cmd.extend(extra_args)
    output = _RunCmd(cmd)

    # "gclient sync" just downloads all of the commits. In order to actually sync
    # to the desired commit, we have to "git reset" to that commit.
    for branch, revision in (revisions or []):
        with misc.ChDir(branch):
            if revision:
                shell_utils.run([GIT, 'reset', '--hard', revision])
            else:
                shell_utils.run([GIT, 'reset', '--hard', 'origin/master'])
    return output
def _RunCmd(cmd):
    """ Run a "gclient ..." command with retries. """
    return shell_utils.run_retry([GCLIENT_PY] + cmd, attempts=3)
示例#8
0
def _RunCmd(cmd):
  """ Run a "gclient ..." command with retries. """
  return shell_utils.run_retry([GCLIENT_PY] + cmd, attempts=3)