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