LogPrinter uses regular `attach()`, not websocket

Fixes #7.
This commit is contained in:
Aanand Prasad 2014-01-13 16:23:10 +00:00
parent b4c905dc83
commit feafea2c6d
2 changed files with 6 additions and 13 deletions

View File

@ -31,28 +31,18 @@ class LogPrinter(object):
def _make_log_generator(self, container, color_fn): def _make_log_generator(self, container, color_fn):
prefix = color_fn(container.name + " | ") prefix = color_fn(container.name + " | ")
websocket = self._attach(container) for line in split_buffer(self._attach(container), '\n'):
return (prefix + line for line in split_buffer(read_websocket(websocket), '\n')) yield prefix + line
def _attach(self, container): def _attach(self, container):
params = { params = {
'stdin': False,
'stdout': True, 'stdout': True,
'stderr': True, 'stderr': True,
'logs': False,
'stream': True, 'stream': True,
} }
params.update(self.attach_params) params.update(self.attach_params)
params = dict((name, 1 if value else 0) for (name, value) in list(params.items())) params = dict((name, 1 if value else 0) for (name, value) in list(params.items()))
return container.attach_socket(params=params, ws=True) return container.attach(**params)
def read_websocket(websocket):
while True:
data = websocket.recv()
if data:
yield data
else:
break
def split_buffer(reader, separator): def split_buffer(reader, separator):
""" """

View File

@ -122,6 +122,9 @@ class Container(object):
links.append(bits[2]) links.append(bits[2])
return links return links
def attach(self, *args, **kwargs):
return self.client.attach(self.id, *args, **kwargs)
def attach_socket(self, **kwargs): def attach_socket(self, **kwargs):
return self.client.attach_socket(self.id, **kwargs) return self.client.attach_socket(self.id, **kwargs)