-
Notifications
You must be signed in to change notification settings - Fork 0
/
adb.py
30 lines (25 loc) · 794 Bytes
/
adb.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
# -*- coding: utf-8 -*-
import os, subprocess, re
WORKDIR = os.path.dirname(os.path.abspath(__file__))
TOOLS_PATH = os.path.join(WORKDIR, 'platform-tools')
def execute(command, wait = True):
process = subprocess.Popen(
'adb' + ' ' + command,
shell = True,
stdout = subprocess.PIPE,
stderr = subprocess.PIPE,
cwd = TOOLS_PATH if os.path.exists(TOOLS_PATH) else None
)
if wait: process.wait()
return process
def read(command, encode = True):
data = execute(command, wait = False).stdout.read()
return data.decode('utf-8') if encode else data
def connect():
if re.search(r'device\s+$', read('devices')):
return True
else:
execute('kill-server')
return False
def kill():
execute('kill-server')