예제 #1
0
    def _generate_binary(self):
        from dmoj.utils import ansi

        # If the executor requires compilation, compile and send any errors/warnings to the site
        try:
            # Fetch an appropriate executor for the language
            binary = executors[self.language].Executor(
                self.problem.id,
                self.source,
                hints=self.problem.config.hints or [],
                unbuffered=self.problem.config.unbuffered)
        except CompileError as compilation_error:
            error = compilation_error.args[0]
            error = error.decode('mbcs') if os.name == 'nt' and isinstance(
                error, six.binary_type) else error
            self.judge.packet_manager.compile_error_packet(
                ansi.format_ansi(error or 'compiler exited abnormally'))

            # Compile error is fatal
            raise

        # Carry on grading in case of compile warning
        if hasattr(binary, 'warning') and binary.warning:
            self.judge.packet_manager.compile_message_packet(
                ansi.format_ansi(binary.warning or ''))
        return binary
예제 #2
0
    def _generate_binary(self):
        from dmoj.utils import ansi

        # If the executor requires compilation, compile and send any errors/warnings to the site
        try:
            # Fetch an appropriate executor for the language
            binary = executors[self.language].Executor(self.problem.id, self.source)
        except CompileError as compilation_error:
            error = compilation_error.args[0]
            error = error.decode('mbcs') if os.name == 'nt' and isinstance(error, str) else error
            self.judge.packet_manager.compile_error_packet(ansi.format_ansi(error))

            # Compile error is fatal
            raise

        # Carry on grading in case of compile warning
        if hasattr(binary, 'warning') and binary.warning:
            self.judge.packet_manager.compile_message_packet(ansi.format_ansi(binary.warning))
        return binary
예제 #3
0
    def _generate_binary(self):
        siggraders = ('C', 'CPP03', 'CPP0X', 'CPP11', 'CPP14', 'CPP17')

        for i in reversed(siggraders):
            if i in executors:
                siggrader = i
                break
        else:
            raise CompileError(
                b"can't signature grade, why did I get this submission?")
        if self.language in siggraders:
            aux_sources = {}
            handler_data = self.problem.config['signature_grader']

            entry_point = self.problem.problem_data[handler_data['entry']]
            header = self.problem.problem_data[handler_data['header']]

            submission_prefix = ('#include "%s"\n'
                                 '#define main main_%s\n') % (
                                     handler_data['header'], str(
                                         uuid.uuid4()).replace('-', ''))

            aux_sources[
                self.problem.id +
                '_submission'] = utf8bytes(submission_prefix) + self.source

            aux_sources[handler_data['header']] = header
            entry = entry_point
            # Compile as CPP regardless of what the submission language is
            try:
                return executors[siggrader].Executor(
                    self.problem.id,
                    entry,
                    aux_sources=aux_sources,
                    writable=handler_data['writable'] or (1, 2),
                    fds=handler_data['fds'],
                    defines=['-DSIGNATURE_GRADER'])
            except CompileError as compilation_error:
                self.judge.packet_manager.compile_error_packet(
                    ansi.format_ansi(compilation_error.args[0]
                                     or 'compiler exited abnormally'))

                # Compile error is fatal
                raise

        self.judge.packet_manager.compile_error_packet(
            'no valid handler compiler exists')
예제 #4
0
파일: signature.py 프로젝트: hhemanth/judge
    def _generate_binary(self):
        siggraders = ('C', 'CPP', 'CPP0X', 'CPP11', 'CPP14')

        for i in reversed(siggraders):
            if i in executors:
                siggrader = i
                break
        else:
            raise CompileError(
                "can't signature grade, why did I get this submission?")
        if self.language in siggraders:
            aux_sources = {}
            handler_data = self.problem.config['signature_grader']

            entry_point = self.problem.problem_data[handler_data['entry']]
            header = self.problem.problem_data[handler_data['header']]

            submission_template = '''#include "%s"
#define main main_%s
%s
'''

            aux_sources[self.problem.id + '_submission'] = \
                (submission_template % (handler_data['header'], str(uuid.uuid4()).replace('-', ''), self.source))

            aux_sources[handler_data['header']] = header
            entry = entry_point
            # Compile as CPP11 regardless of what the submission language is
            try:
                return executors[siggrader].Executor(
                    self.problem.id,
                    entry,
                    aux_sources=aux_sources,
                    writable=handler_data['writable'] or (1, 2),
                    fds=handler_data['fds'])
            except CompileError as compilation_error:
                self.judge.packet_manager.compile_error_packet(
                    ansi.format_ansi(compilation_error.message))

                # Compile error is fatal
                raise

        self.judge.packet_manager.compile_error_packet(
            'no valid handler compiler exists')
예제 #5
0
파일: signature.py 프로젝트: DMOJ/judge
    def _generate_binary(self):
        siggraders = ('C', 'CPP03', 'CPP0X', 'CPP11', 'CPP14', 'CPP17')

        for i in reversed(siggraders):
            if i in executors:
                siggrader = i
                break
        else:
            raise CompileError(b"can't signature grade, why did I get this submission?")
        if self.language in siggraders:
            aux_sources = {}
            handler_data = self.problem.config['signature_grader']

            entry_point = self.problem.problem_data[handler_data['entry']]
            header = self.problem.problem_data[handler_data['header']]

            submission_prefix = (
                '#include "%s"\n'
                '#define main main_%s\n'
            ) % (handler_data['header'], str(uuid.uuid4()).replace('-', ''))

            aux_sources[self.problem.id + '_submission'] = utf8bytes(submission_prefix) + self.source

            aux_sources[handler_data['header']] = header
            entry = entry_point
            # Compile as CPP regardless of what the submission language is
            try:
                return executors[siggrader].Executor(self.problem.id, entry, aux_sources=aux_sources,
                                                     writable=handler_data['writable'] or (1, 2),
                                                     fds=handler_data['fds'], defines=['-DSIGNATURE_GRADER'])
            except CompileError as compilation_error:
                self.judge.packet_manager.compile_error_packet(ansi.format_ansi(
                    compilation_error.args[0] or 'compiler exited abnormally'
                ))

                # Compile error is fatal
                raise

        self.judge.packet_manager.compile_error_packet('no valid handler compiler exists')