Exemplo n.º 1
0
    def compile(self, timeout=20):
        """Return True if compilation succeeds, False otherwise."""

        if self.compiled:
            return True

        # TODO run async
        try:
            backports.sp_run(self.sandboxed_compile_cmd, check=True,
                             timeout=timeout, stdout=sp.PIPE, stderr=sp.PIPE)
            self.compiled = True
            return True
        except sp.SubprocessError as error:
            error = '{error}\nStdout: {stdout}\nStderr: {stderr}'.format(
                error=error,
                stdout=error.output.decode('utf8').rstrip(),
                stderr=error.stderr.decode('utf8').rstrip())
            logging.warning(error)
            self.compile_errors = error
            return False
Exemplo n.º 2
0
    def compile(self, timeout=20):
        """Return True if compilation succeeds, False otherwise."""

        if self.compiled:
            return True

        # TODO run async
        try:
            backports.sp_run(self.sandboxed_compile_cmd,
                             check=True,
                             timeout=timeout,
                             stdout=sp.PIPE,
                             stderr=sp.PIPE)
            self.compiled = True
            return True
        except sp.SubprocessError as error:
            error = '{error}\nStdout: {stdout}Stderr: {stderr}'.format(
                error=error,
                stdout=error.stdout.decode('utf8'),
                stderr=error.stderr.decode('utf8'))
            logging.warning(error)
            self.compile_errors = error
            return False
Exemplo n.º 3
0
def generate_graph(player_names):
    script = os.path.join(config.BASE_DIR, 'scripts', 'generate_graph.sh')
    input_ = b'\n'.join(name.encode('utf8') for name in player_names)
    try:
        process = backports.sp_run([script, str(GRAPH_WANDERLUST)],
                                   input=input_, stdout=sp.PIPE,
                                   stderr=sp.PIPE, check=True,
                                   timeout=GRAPH_GENERATION_TIMEOUT)
    except sp.SubprocessError as error:
        logging.error('Graph generation failed.')
        logging.error(error)
        logging.error('Stdout was %s', error.output.decode('utf8'))
        logging.error('Stderr was %s', error.stderr.decode('utf8'))
        raise

    return [line.decode('utf8') for line in process.stdout.splitlines()]