summaryrefslogtreecommitdiffstats
path: root/build/android/devil/android/sdk/aapt.py
blob: 62b37d7461a649922efb2a4f1b9010f3dbf29b8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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.

"""This module wraps the Android Asset Packaging Tool."""

from devil import devil_env
from devil.utils import cmd_helper


def _RunAaptCmd(args):
  """Runs an aapt command.

  Args:
    args: A list of arguments for aapt.

  Returns:
    The output of the command.
  """
  aapt_path = devil_env.config.FetchPath('aapt')
  cmd = [aapt_path] + args
  status, output = cmd_helper.GetCmdStatusAndOutput(cmd)
  if status != 0:
    raise Exception('Failed running aapt command: "%s" with output "%s".' %
                    (' '.join(cmd), output))
  return output


def Dump(what, apk, assets=None):
  """Returns the output of the aapt dump command.

  Args:
    what: What you want to dump.
    apk: Path to apk you want to dump information for.
    assets: List of assets in apk you want to dump information for.
  """
  assets = assets or []
  if isinstance(assets, basestring):
    assets = [assets]
  return _RunAaptCmd(['dump', what, apk] + assets).splitlines()