mirror of
https://github.com/imcarlost/pidcat-repl.git
synced 2026-08-08 23:17:43 -04:00
Use subprocess for adb command. Do not fail if we can't get terminal size.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python -u
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Copyright 2009, The Android Open Source Project
|
Copyright 2009, The Android Open Source Project
|
||||||
@@ -25,9 +25,8 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
import fcntl
|
import subprocess
|
||||||
import termios
|
from subprocess import PIPE
|
||||||
import struct
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Filter logcat by package name')
|
parser = argparse.ArgumentParser(description='Filter logcat by package name')
|
||||||
parser.add_argument('package', nargs='+', help='Application package name(s)')
|
parser.add_argument('package', nargs='+', help='Application package name(s)')
|
||||||
@@ -38,9 +37,13 @@ args = parser.parse_args()
|
|||||||
|
|
||||||
header_size = args.tag_width + 1 + 3 + 1 # space, level, space
|
header_size = args.tag_width + 1 + 3 + 1 # space, level, space
|
||||||
|
|
||||||
# unpack the current terminal width/height
|
width = -1
|
||||||
data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234')
|
try:
|
||||||
HEIGHT, WIDTH = struct.unpack('hh',data)
|
# Get the current terminal width
|
||||||
|
import fcntl, termios, struct
|
||||||
|
h, width = struct.unpack('hh', fcntl.ioctl(0, termios.TIOCGWINSZ, struct.pack('hh', 0, 0)))
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
|
BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)
|
||||||
|
|
||||||
@@ -56,7 +59,9 @@ def colorize(message, fg=None, bg=None):
|
|||||||
return termcolor(fg, bg) + message + RESET
|
return termcolor(fg, bg) + message + RESET
|
||||||
|
|
||||||
def indent_wrap(message):
|
def indent_wrap(message):
|
||||||
wrap_area = WIDTH - header_size
|
if width == -1:
|
||||||
|
return message
|
||||||
|
wrap_area = width - header_size
|
||||||
messagebuf = ''
|
messagebuf = ''
|
||||||
current = 0
|
current = 0
|
||||||
while current < len(message):
|
while current < len(message):
|
||||||
@@ -120,10 +125,11 @@ PID_START = re.compile(r'^Start proc ([a-zA-Z0-9._:]+) for ([a-z]+ [^:]+): pid=(
|
|||||||
PID_KILL = re.compile(r'^Killing (\d+):([a-zA-Z0-9._]+)/[^:]+: (.*)\r?$')
|
PID_KILL = re.compile(r'^Killing (\d+):([a-zA-Z0-9._]+)/[^:]+: (.*)\r?$')
|
||||||
PID_LEAVE = re.compile(r'^No longer want ([a-zA-Z0-9._]+) \(pid (\d+)\): .*\r?$')
|
PID_LEAVE = re.compile(r'^No longer want ([a-zA-Z0-9._]+) \(pid (\d+)\): .*\r?$')
|
||||||
PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._]+) \(pid (\d+)\) has died.?\r$')
|
PID_DEATH = re.compile(r'^Process ([a-zA-Z0-9._]+) \(pid (\d+)\) has died.?\r$')
|
||||||
LOG_LINE = re.compile(r'^([A-Z])/([^\(]+)\( *(\d+)\): (.*)\r?$')
|
LOG_LINE = re.compile(r'^([A-Z])/([^\(]+)\( *(\d+)\): (.*?)\r?$')
|
||||||
BUG_LINE = re.compile(r'^(?!.*(nativeGetEnabledTags)).*$')
|
BUG_LINE = re.compile(r'^(?!.*(nativeGetEnabledTags)).*$')
|
||||||
|
|
||||||
input = os.popen('adb logcat')
|
adb_command = ['adb', 'logcat']
|
||||||
|
adb = subprocess.Popen(adb_command, stdin=PIPE, stdout=PIPE, stderr=PIPE)
|
||||||
pids = set()
|
pids = set()
|
||||||
last_tag = None
|
last_tag = None
|
||||||
|
|
||||||
@@ -151,9 +157,9 @@ def parse_death(tag, message):
|
|||||||
return pid
|
return pid
|
||||||
return None
|
return None
|
||||||
|
|
||||||
while True:
|
while adb.poll() is None:
|
||||||
try:
|
try:
|
||||||
line = input.readline()
|
line = adb.stdout.readline()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
break
|
break
|
||||||
if len(line) == 0:
|
if len(line) == 0:
|
||||||
|
|||||||
Reference in New Issue
Block a user