Home | History | Annotate | Download | only in android_commands
      1 import os, subprocess, tempfile
      2 import time
      3 
      4 ANDROID_TMPDIR = '/data/local/tmp/Output'
      5 ADB = os.environ.get('ADB', 'adb')
      6 
      7 verbose = False
      8 if os.environ.get('ANDROID_RUN_VERBOSE') == '1':
      9     verbose = True
     10 
     11 def adb(args):
     12     if verbose:
     13         print args
     14     devnull = open(os.devnull, 'w')
     15     return subprocess.call([ADB] + args, stdout=devnull, stderr=subprocess.STDOUT)
     16 
     17 def pull_from_device(path):
     18     tmp = tempfile.mktemp()
     19     adb(['pull', path, tmp])
     20     text = open(tmp, 'r').read()
     21     os.unlink(tmp)
     22     return text
     23 
     24 def push_to_device(path):
     25     # Workaround for https://code.google.com/p/android/issues/detail?id=65857
     26     dst_path = os.path.join(ANDROID_TMPDIR, os.path.basename(path))
     27     tmp_path = dst_path + '.push'
     28     adb(['push', path, tmp_path])
     29     adb(['shell', 'cp "%s" "%s" 2>&1' % (tmp_path, dst_path)])
     30