Beispiel #1
0
def CreateAvd(avdName, abi):
  out = utils.RunCommand(["android", "create", "avd", "--name", avdName,
                          "--target", TargetForAbi(abi), '--abi', abi],
                         input="no\n")
  if out.find('Created AVD ') < 0:
    if VERBOSE:
        sys.stderr.write('Could not create AVD:\n%s\n' % out)
    raise utils.Error('Could not create AVD')
Beispiel #2
0
def EnsureSdkPackageInstalled(packages, key):
  """
  Makes sure the package with a given key is installed.

  key is (id-key, type, description-prefix)

  Returns True if the package was not already installed.
  """
  entry = AndroidSdkFindPackage(packages, key)
  if entry is None:
    raise utils.Error("Could not find a package for key %s" % key)
  packageId = entry[0]
  if VERBOSE:
    sys.stderr.write('Checking Android SDK package %s...\n' % str(entry))
  out = utils.RunCommand(
      ["android", "update", "sdk", "-a", "-u", "--filter", str(packageId)])
  return '\nInstalling Archives:\n' in out
Beispiel #3
0
def SdkPackagesForAbi(abi):
  packagesForAbi = {
    'armeabi-v7a': [
      # The platform needed to install the armeabi ABI system image:
      ('android-15', 'Platform',  'Android SDK Platform 4.0.3'),
      # The armeabi-v7a ABI system image:
      ('sysimg-15', 'SystemImage',  'Android SDK Platform 4.0.3')
    ],
    'x86': [
      # The platform needed to install the x86 ABI system image:
      ('android-15', 'Platform',  'Android SDK Platform 4.0.3'),
      # The x86 ABI system image:
      ('sysimg-15', 'SystemImage',  'Android SDK Platform 4.0.4')
    ]
  }

  if abi not in packagesForAbi:
    raise utils.Error('Unsupported abi %s' % abi)
  return packagesForAbi[abi]
Beispiel #4
0
def ParseAndroidListSdkResult(text):
  """
  Parse the output of an 'android list sdk' command.

  Return list of (id-num, id-key, type, description).
  """
  header_regex = re.compile(
      r'Packages available for installation or update: \d+\n')
  packages = re.split(header_regex, text)
  if len(packages) != 2:
    raise utils.Error("Could not get a list of packages to install")
  entry_regex = re.compile(
      r'^id\: (\d+) or "([^"]*)"\n\s*Type\: ([^\n]*)\n\s*Desc\: (.*)')
  entries = []
  for entry in packages[1].split('----------\n'):
    match = entry_regex.match(entry)
    if match == None:
      continue
    entries.append((int(match.group(1)), match.group(2), match.group(3),
        match.group(4)))
  return entries
Beispiel #5
0
 def _InvokeTool(self, project, name, *arguments):
     location = self._GetLocation(project)
     tool = path.relpath(self._GetTool(name), location)
     command_array = [tool]
     for argument in arguments:
         command_array.append(str(argument))
     stdout = subprocess.PIPE
     if self._verbose:
         print 'Invoking', ' '.join(command_array)
         print 'in', location
         stdout = None  # In verbose mode we want to see the output from the tool.
     proc = subprocess.Popen(command_array,
                             cwd=location,
                             stdout=stdout,
                             stderr=subprocess.STDOUT)
     stdout = proc.communicate()[0]
     exit_code = proc.wait()
     if exit_code != 0:
         sys.stderr.write(stdout)
         raise utils.Error('%s returned %s' % (name, exit_code))
     elif self._verbose:
         print name, 'returned', exit_code
Beispiel #6
0
def ParseAndroidListAvdResult(text):
  """
  Parse the output of an 'android list avd' command.
  Return List of {Name: Path: Target: ABI: Skin: Sdcard:}
  """
  text = text.split('Available Android Virtual Devices:\n')[-1]
  text = text.split(
      'The following Android Virtual Devices could not be loaded:\n')[0]
  result = []
  line_re = re.compile(r'^\s*([^\:]+)\:\s*(.*)$')
  for chunk in text.split('\n---------\n'):
    entry = {}
    for line in chunk.split('\n'):
      line = line.strip()
      if len(line) == 0:
        continue
      match = line_re.match(line)
      if match is None:
        raise utils.Error('Match failed')
      entry[match.group(1)] = match.group(2)
    if len(entry) > 0:
      result.append(entry)
  return result
Beispiel #7
0
 def _GetLocation(self, *arguments):
     location = path.join(self._top_dir, *arguments)
     if not path.exists(location):
         raise utils.Error('%s: does not exist' % location)
     return location
Beispiel #8
0
 def _EnsureExists(self, artifact):
     if not path.exists(artifact):
         raise utils.Error('%s: does not exist' % artifact)