1 import os
, sys
, subprocess
, tempfile
4 ANDROID_TMPDIR
= "/data/local/tmp/Output"
5 ADB
= os
.environ
.get("ADB", "adb")
8 if os
.environ
.get("ANDROID_RUN_VERBOSE") == "1":
12 def host_to_device_path(path
):
13 rel
= os
.path
.relpath(path
, "/")
14 dev
= os
.path
.join(ANDROID_TMPDIR
, rel
)
18 def adb(args
, attempts
=1, timeout_sec
=600):
21 tmpname
= tempfile
.mktemp()
22 out
= open(tmpname
, "w")
24 while attempts
> 0 and ret
!= 0:
26 ret
= subprocess
.call(
27 ["timeout", str(timeout_sec
), ADB
] + args
,
29 stderr
=subprocess
.STDOUT
,
32 print("adb command failed", args
)
35 out
= open(tmpname
, "r")
42 def pull_from_device(path
):
43 tmp
= tempfile
.mktemp()
44 adb(["pull", path
, tmp
], 5, 60)
45 text
= open(tmp
, "r").read()
50 def push_to_device(path
):
51 dst_path
= host_to_device_path(path
)
52 adb(["push", path
, dst_path
], 5, 60)