Example #1
0
def test_async_scrollable_listbox(inp, expected):
    ui = flexmock(refresh=lambda: None)
    lb = AsyncScrollableListBox(inp, ui)
    lb.thread.join()
    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
Example #2
0
def test_async_scrollable_listbox(inp, expected):
    ui = flexmock(refresh=lambda: None)
    lb = AsyncScrollableListBox(inp, ui)
    lb.thread.join()
    canvas = lb.render((SCREEN_WIDTH, SCREEN_HEIGHT))
    text = [bytes().join([t for at, cs, t in ln]) for ln in canvas.content()]
    w = "{:%d}" % SCREEN_WIDTH
    s = w.format("{}".format("No more logs."))
    expected[4] = s.encode("utf-8")
    assert text == expected
Example #3
0
def test_async_scrollable_listbox(inp, expected):
    ui = flexmock(refresh=lambda: None)
    lb = AsyncScrollableListBox(inp, ui)
    lb.thread.join()
    canvas = lb.render((SCREEN_WIDTH, SCREEN_HEIGHT))
    text = [bytes().join([t for at, cs, t in ln]) for ln in canvas.content()]
    w = "{:%d}" % SCREEN_WIDTH
    s = w.format("{}".format("No more logs."))
    expected[4] = s.encode("utf-8")
    assert text == expected
Example #4
0
File: buffer.py Project: rm3l/sen
    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__()