Home | History | Annotate | Download | only in sdk
      1 # Copyright 2015 The Chromium Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 """This module wraps the Android Asset Packaging Tool."""
      6 
      7 from devil.android.sdk import build_tools
      8 from devil.utils import cmd_helper
      9 from devil.utils import lazy
     10 
     11 
     12 _aapt_path = lazy.WeakConstant(lambda: build_tools.GetPath('aapt'))
     13 
     14 
     15 def _RunAaptCmd(args):
     16   """Runs an aapt command.
     17 
     18   Args:
     19     args: A list of arguments for aapt.
     20 
     21   Returns:
     22     The output of the command.
     23   """
     24   cmd = [_aapt_path.read()] + args
     25   status, output = cmd_helper.GetCmdStatusAndOutput(cmd)
     26   if status != 0:
     27     raise Exception('Failed running aapt command: "%s" with output "%s".' %
     28                     (' '.join(cmd), output))
     29   return output
     30 
     31 
     32 def Dump(what, apk, assets=None):
     33   """Returns the output of the aapt dump command.
     34 
     35   Args:
     36     what: What you want to dump.
     37     apk: Path to apk you want to dump information for.
     38     assets: List of assets in apk you want to dump information for.
     39   """
     40   assets = assets or []
     41   if isinstance(assets, basestring):
     42     assets = [assets]
     43   return _RunAaptCmd(['dump', what, apk] + assets).splitlines()
     44