-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadb_base.py
51 lines (35 loc) · 1.25 KB
/
adb_base.py
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
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/python3
from subprocess import Popen, PIPE;
from os import environ
from os.path import dirname
def popen_proc(cmd):
p = Popen(cmd, stdout=PIPE, stderr=PIPE);
return p.communicate(), p
def popen_shell(cmd):
print("-" * 20, "INTERACTIVE", "-"*20)
p = Popen(cmd)
return (0, 0), p
def adb_exec(cmd, live_output=False):
#adb_path = environ["ANDROID_SDK"] + "/platform-tools/adb"
adb_path = "adb"
if live_output:
return popen_shell([adb_path] + cmd)
else:
return popen_proc([adb_path] + cmd)
def monkeyrun(script, args):
monkeyrunner_bin = environ["ANDROID_SDK"] + "/tools/bin/monkeyrunner"
return popen_proc([monkeyrunner_bin, dirname(__file__) + "/" + script] + args)
def adb_dev_exec(dev, cmd, live_output=False):
if live_output:
(stdout, stderr), p = adb_exec(["-s", dev]+cmd, True)
else:
(stdout, stderr), p = adb_exec(["-s", dev]+cmd)
p.wait()
if live_output:
print("-" * 20, "END INTERACTIVE", "-"*20)
if p.returncode != 0:
print(stdout.decode())
raise RuntimeError(stderr.decode())
return stdout.decode().replace('\r\n','\n')
def adb_get_prop(dev, prop):
return adb_dev_exec(dev, ["shell", "getprop", prop]).replace('\n', '')