def __init__(self, ui, docker_object, follow=False): """ :param docker_object: container to display logs :param ui: ui object so we can refresh """ self.display_name += "({})".format(docker_object.short_name) if isinstance(docker_object, DockerContainer): try: pre_message = "Getting logs for container {}...".format( docker_object.short_name) ui.notify_message(pre_message) if follow: # FIXME: this is a bit race-y -- we might lose some logs with this approach operation = docker_object.logs(follow=follow, lines=0) static_data = docker_object.logs(follow=False).response self.widget = AsyncScrollableListBox( operation.response, ui, static_data=static_data) else: operation = docker_object.logs(follow=follow) self.widget = ScrollableListBox(ui, operation.response) ui.remove_notification_message(pre_message) ui.notify_widget( get_operation_notify_widget(operation, display_always=False)) except Exception as ex: # FIXME: let's catch 404 and print that container doesn't exist # instead of printing ugly HTTP error raise NotifyError("Error getting logs for container %s: %r" % (docker_object, ex)) else: raise NotifyError("Only containers have logs.") super().__init__()
def __init__(self, ui, docker_object): """ :param docker_object: object to inspect """ inspect_data = docker_object.display_inspect() self.widget = ScrollableListBox(ui, inspect_data) self.display_name += docker_object.short_name super().__init__()
def test_scrollable_listbox(inp, expected): lb = ScrollableListBox(MockUI(), inp) canvas = lb.render((SCREEN_WIDTH, SCREEN_HEIGHT)) text = [bytes().join([t for at, cs, t in ln]) for ln in canvas.content()] assert text == expected
def refresh(self): inspect_data = self.docker_object.display_inspect() self.widget = ScrollableListBox(self.ui, inspect_data)