Exemplo n.º 1
0
Arquivo: buffer.py Projeto: f-cap/sen
    def __init__(self, ui, docker_object, follow=False):
        """

        :param docker_object: container to display logs
        :param ui: ui object so we refresh
        """
        self.tag = "F" if follow else "L"
        self.display_name = 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__()
Exemplo n.º 2
0
Arquivo: buffer.py Projeto: 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__()
Exemplo n.º 3
0
 def do(self, fn_name, pre_message=None, notif_level="info"):
     pre_message = pre_message or self.pre_info_message.format(
         container_name=self.docker_object.short_name)
     self.ui.notify_message(pre_message)
     try:
         operation = getattr(self.docker_object, fn_name)()
     except AttributeError:
         log_txt = "you can't {} {}".format(fn_name, self.docker_object)
         logger.error(log_txt)
         notif_txt = "You can't {} {} {!r}.".format(
             fn_name, self.docker_object.pretty_object_type.lower(),
             self.docker_object.short_name)
         self.ui.notify_message(notif_txt, level="error")
     except Exception as ex:
         self.ui.notify_message(str(ex), level="error")
         raise
     else:
         self.ui.remove_notification_message(pre_message)
         self.ui.notify_widget(
             get_operation_notify_widget(operation,
                                         notif_level=notif_level))
Exemplo n.º 4
0
 def run_and_report_on_fail(fn_name, docker_object, pre_message,
                            notif_level="info"):
     self.ui.notify_message(pre_message)
     try:
         operation = getattr(docker_object, fn_name)()
     except AttributeError:
         log_txt = "you can't {} {}".format(fn_name, docker_object)
         logger.error(log_txt)
         notif_txt = "You can't {} {} {!r}.".format(
             fn_name,
             docker_object.pretty_object_type.lower(),
             docker_object.short_name)
         self.ui.notify_message(notif_txt, level="error")
     except Exception as ex:
         self.ui.notify_message(str(ex), level="error")
         raise
     else:
         self.ui.remove_notification_message(pre_message)
         self.ui.notify_widget(
             get_operation_notify_widget(operation, notif_level=notif_level)
         )
Exemplo n.º 5
0
 def do(self, fn_name, pre_message=None, notif_level="info"):
     pre_message = pre_message or self.pre_info_message.format(
         container_name=self.docker_object.short_name)
     self.ui.notify_message(pre_message)
     try:
         operation = getattr(self.docker_object, fn_name)()
     except AttributeError:
         log_txt = "you can't {} {}".format(fn_name, self.docker_object)
         logger.error(log_txt)
         notif_txt = "You can't {} {} {!r}.".format(
             fn_name,
             self.docker_object.pretty_object_type.lower(),
             self.docker_object.short_name)
         self.ui.notify_message(notif_txt, level="error")
     except Exception as ex:
         self.ui.notify_message(str(ex), level="error")
         raise
     else:
         self.ui.remove_notification_message(pre_message)
         self.ui.notify_widget(
             get_operation_notify_widget(operation, notif_level=notif_level)
         )
Exemplo n.º 6
0
 def query_notify(operation):
     w = get_operation_notify_widget(operation, display_always=False)
     if w:
         self.ui.notify_widget(w)