Пример #1
0
def pipe_chunk_to_command(command, chunk):
    """
    Executes the given command, passing the chunk to its stdin via buf_size buffers.
    """
    logger = logging.getLogger(__name__)
    sys.stdout.buffer.write(f"Piping chunk | {command}\n".encode('utf8'))
    sys.stdout.flush()
    child = spawn(command)
    child.logfile_read = sys.stdout.buffer
    for buf in chunk:
        child.send(buf)
    child.sendeof()
    child.expect(EOF)
    retcode = child.wait()
    logger.debug(f"Process returned {retcode}")
    return retcode
Пример #2
0
    def setup(self):
        cmdls = [
            key + "=\"" + self.session_vars[key] + "\""
            for key in self.session_vars.keys()
        ]

        if self.exec_profile["type"] == "bash":
            init_pref = ""
        elif self.exec_profile["type"] == "powershell":
            init_pref = "$"
        else:
            raise AssertionError("Error unkown type \"" +
                                 self.exec_profile["type"] + "\".")

        cmdls = [(init_pref + c) for c in cmdls]
        self.pexpect_process = spawn(self.exec_profile["type"], timeout=None)
        self.send_commands(cmdls)
def prepare_shell():
    var_cmdls = [
        "JOB_ID=\"" + job_id + "\"", "RUN_ID=\"" + run_id + "\"",
        "CWL=\"" + cwl + "\"", "RUN_YAML=\"" + yaml + "\"",
        "OUTPUT_DIR=\"" + out_dir + "\"",
        "GLOBAL_TEMP_DIR=\"" + global_temp_dir + "\"",
        "LOG_FILE=\"" + log + "\"", "SUCCESS=\"True\"", "ERR_MESSAGE=\"None\"",
        "FINISH_TAG=\"DONE\"", "PYTHON_PATH=\"" + python_interpreter + "\""
    ]

    if exec_profile["shell"] == "bash":
        init_pref = ""
    elif exec_profile["shell"] == "powershell":
        init_pref = "$"
    else:
        sys.exit("Error unkown shell \"" + exec_profile["shell"] + "\".")

    var_cmdls = [(init_pref + c) for c in var_cmdls]
    p = spawn(exec_profile["shell"], timeout=None)
    [p.sendline(cmdl) for cmdl in var_cmdls]

    return p