Esempio n. 1
0
def pipe_output_to_http(output_stream, bash_formatting, write_callback):
    reader = None
    if bash_formatting:
        reader = bash_utils.BashReader()

    class OutputToHttpListener:
        def on_next(self, output):
            if reader:
                read_iterator = reader.read(output)
                for text in read_iterator:
                    write_callback(
                        wrap_script_output(text.text, text.text_color,
                                           text.background_color, text.styles))

            else:
                write_callback(wrap_script_output(output))

        def on_close(self):
            pass

    output_stream.subscribe(OutputToHttpListener())
Esempio n. 2
0
def pipe_process_to_http(process_wrapper: execution_base.ProcessWrapper, output_logger, write_callback):
    bash_formatting = process_wrapper.get_config().is_bash_formatting()

    reader = None
    if bash_formatting:
        reader = bash_utils.BashReader()

    while True:
        process_output = process_wrapper.read()

        output_logger.log(process_output)

        if process_output is not None:
            if reader:
                read_iterator = reader.read(process_output)
                for text in read_iterator:
                    write_callback(wrap_script_output(
                        text.text,
                        text.text_color,
                        text.background_color,
                        text.styles
                    ))

            else:
                write_callback(wrap_script_output(process_output))

        elif process_wrapper.is_finished():
            if reader:
                remaining_text = reader.get_current_text()
                if remaining_text:
                    write_callback(wrap_script_output(
                        remaining_text.text,
                        remaining_text.text_color,
                        remaining_text.background_color,
                        remaining_text.styles
                    ))

            break