ZFS Automatic Snapshot Daemon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

30 lines
794 B

import asyncio
class LineBufferedProtocol(asyncio.SubprocessProtocol):
def __init__(self, encoding):
self.encoding = encoding
self.buffer = bytearray()
def pipe_data_received(self, fd, data):
self.buffer.extend(data)
try:
while True:
length = self.buffer.index(b'\n')
line = self.buffer[0: length].decode()
del self.buffer[0: length + 1]
self.pipe_line_received(line)
except ValueError:
pass
def pipe_line_received(self, line):
pass
def process_exited(self):
if(len(self.buffer) > 0):
line = self.buffer.decode()
self.buffer = bytearray()
self.pipe_line_received(line)