[~] Refactor
This commit is contained in:
parent
b74512eddb
commit
af9345a403
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env python3
|
||||
import enum
|
||||
import collections
|
||||
import datetime
|
||||
import functools
|
||||
import io
|
||||
@ -83,8 +84,8 @@ def intercept_output(
|
||||
t1.register(current_subprocess.stdout, select.POLLIN)
|
||||
#print([current_subprocess, current_subprocess.poll()])
|
||||
output = []
|
||||
buffer = []
|
||||
buffer_lines = []
|
||||
buffer = collections.deque()
|
||||
buffer_lines = collections.deque()
|
||||
|
||||
last_data = None
|
||||
|
||||
@ -107,25 +108,24 @@ def intercept_output(
|
||||
buffer.append(t3)
|
||||
|
||||
if need_lines:
|
||||
if len(buffer_lines) > 0:
|
||||
yield dict(
|
||||
aggegated=False,
|
||||
line=buffer_lines[0],
|
||||
)
|
||||
del buffer_lines[0]
|
||||
|
||||
if b'\n' in t3:
|
||||
t3_pos = t3.rfind(b'\n')
|
||||
buffer_lines.extend([
|
||||
o + b'\n'
|
||||
for o in b''.join(
|
||||
buffer[:-1] + [
|
||||
list(buffer)[:-1] + [
|
||||
t3[:t3_pos]
|
||||
],
|
||||
).splitlines()
|
||||
])
|
||||
del buffer[:-1]
|
||||
buffer[0] = t3[t3_pos + 1:]
|
||||
buffer.clear()
|
||||
buffer.append(t3[t3_pos + 1:])
|
||||
while len(buffer_lines) > 0:
|
||||
yield dict(
|
||||
aggegated=False,
|
||||
line=buffer_lines.popleft(),
|
||||
)
|
||||
|
||||
else:
|
||||
yield dict(
|
||||
data=t3,
|
||||
@ -1466,6 +1466,7 @@ def pm_service(argv):
|
||||
cmd = None
|
||||
if 'powerd' in line:
|
||||
cmd = line
|
||||
print(cmd)
|
||||
|
||||
#cmd = subprocess.check_output(r'''
|
||||
# log stream | grep --line-buffered -i \
|
||||
|
Loading…
Reference in New Issue
Block a user