-
Notifications
You must be signed in to change notification settings - Fork 29
/
logcat.py
54 lines (47 loc) · 1.71 KB
/
logcat.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
52
53
54
import queue
import threading
import subprocess
from gui import *
from GlobalVariables import *
import time
from PyQt5.QtCore import QThread
class AsynchronousFileRead(QThread):
def __init__(self, fd, queueobj):
assert isinstance(queueobj, queue.Queue)
assert callable(fd.readline)
QThread.__init__(self)
self._fd = fd
self._queue = queueobj
def run(self):
'''The body of the tread: read lines and put them on the queue.'''
for line in iter(self._fd.readline, ''):
QThread.msleep(10)
if GlobalVariables.isClose:
break
self._queue.put(line)
def eof(self):
'''Check whether there is no more content to expect.'''
return not self.isRunning() and self._queue.empty()
class Logcat(QThread):
def __init__(self, mainWin, device):
self.mainWin = mainWin
self.device=device
QThread.__init__(self)
def run(self):
cmd="adb -s "+self.device+" logcat"
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
self.stdout_queue = queue.Queue()
self.stdout_reader = AsynchronousFileRead(process.stdout, self.stdout_queue)
self.stdout_reader.start()
time.sleep(1)
while not self.stdout_reader.eof():
line=''
if GlobalVariables.isClose:
break
while not self.stdout_queue.empty():
line+=self.stdout_queue.get().decode(encoding='unicode_escape')
if line:
self.mainWin.txtLogcat.append(line.strip())
time.sleep(1)
print ("Wait to stop logcat.....")
self.stdout_reader.join()