Example #1
0
 def _connect(self):
     self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
     self.conn.connect((self.host, self.port))
     self.input = self.conn.makefile('r')
     self.output = self.conn.makefile('w', 0)
     self.handshake(get_supported_problems(), self.name, self.key)
Example #2
0
File: packet.py Project: DMOJ/judge
    def _connect(self):
        problems = get_supported_problems()
        versions = get_runtime_versions()

        log.info('Opening connection to: [%s]:%s', self.host, self.port)

        while True:
            try:
                self.conn = socket.create_connection((self.host, self.port), timeout=5)
            except OSError as e:
                if e.errno != errno.EINTR:
                    raise
            else:
                break

        self.conn.settimeout(300)
        self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

        if self.ssl_context:
            log.info('Starting TLS on: [%s]:%s', self.host, self.port)
            self.conn = self.ssl_context.wrap_socket(self.conn, server_hostname=self.host)

        log.info('Starting handshake with: [%s]:%s', self.host, self.port)
        self.input = self.conn.makefile('rb')
        self.output = self.conn.makefile('wb', 0)
        self.handshake(problems, versions, self.name, self.key)
        log.info('Judge "%s" online: [%s]:%s', self.name, self.host, self.port)
Example #3
0
    def execute(self, line):
        global submission_id_counter, graded_submissions

        args = self.arg_parser.parse_args(line)

        submission_id_counter += 1
        try:
            id, lang, src, tl, ml = graded_submissions[args.submission_id - 1]
        except IndexError:
            print ansi_style("#ansi[invalid submission '%d'](red|bold)\n" % (args.submission_id - 1))
            return

        id = args.problem or id
        lang = args.language or lang
        tl = args.time_limit or tl
        ml = args.memory_limit or ml

        err = None
        if id not in map(itemgetter(0), judgeenv.get_supported_problems()):
            err = "unknown problem '%s'" % id
        elif lang not in executors:
            err = "unknown language '%s'" % lang
        elif tl <= 0:
            err = '--time-limit must be >= 0'
        elif ml <= 0:
            err = '--memory-limit must be >= 0'
        if err:
            print ansi_style('#ansi[%s](red|bold)\n' % err)
            return

        graded_submissions.append((id, lang, src, tl, ml))
        self.judge.begin_grading(submission_id_counter, id, lang, src, tl, ml, False, blocking=True)
Example #4
0
    def execute(self, line):
        global submission_id_counter, graded_submissions

        args = self.arg_parser.parse_args(line)

        problem_id = args.problem_id
        language_id = args.language_id
        time_limit = args.time_limit
        memory_limit = args.memory_limit

        err = None
        if problem_id not in map(itemgetter(0),
                                 judgeenv.get_supported_problems()):
            err = "unknown problem '%s'" % problem_id
        elif language_id not in executors:
            err = "unknown language '%s'" % language_id
        elif time_limit <= 0:
            err = '--time-limit must be >= 0'
        elif memory_limit <= 0:
            err = '--memory-limit must be >= 0'
        if not err:
            if args.source_file:
                try:
                    with open(os.path.realpath(args.source_file), 'r') as f:
                        src = f.read()
                except Exception as io:
                    err = str(io)
            else:
                src = []
                try:
                    while True:
                        s = raw_input()
                        if s.strip() == ':q':
                            raise EOFError
                        src.append(s)
                except EOFError:  # Ctrl+D
                    src = '\n'.join(src)
                except Exception as io:
                    err = str(io)
        if err:
            print ansi_style('#ansi[%s](red|bold)\n' % err)
            return

        submission_id_counter += 1
        graded_submissions.append(
            (problem_id, language_id, src, time_limit, memory_limit))
        self.judge.begin_grading(submission_id_counter,
                                 problem_id,
                                 language_id,
                                 src,
                                 time_limit,
                                 memory_limit,
                                 False,
                                 False,
                                 blocking=True)
Example #5
0
    def execute(self, line):
        args = self.arg_parser.parse_args(line)

        problem_id = args.problem_id
        language_id = args.language_id
        time_limit = args.time_limit
        memory_limit = args.memory_limit
        source_file = args.source_file

        if language_id not in executors:
            source_file = language_id
            language_id = None  # source file / language id optional

        if problem_id not in map(itemgetter(0),
                                 judgeenv.get_supported_problems()):
            raise InvalidCommandException("unknown problem '%s'" % problem_id)
        elif not language_id:
            if source_file:
                filename, dot, ext = source_file.partition('.')
                if not ext:
                    raise InvalidCommandException('invalid file name')
                else:
                    # TODO: this should be a proper lookup elsewhere
                    ext = ext.upper()
                    language_id = {
                        'PY': 'PY2',
                        'CPP': 'CPP11',
                        'JAVA': 'JAVA8'
                    }.get(ext, ext)
            else:
                raise InvalidCommandException("no language is selected")
        elif language_id not in executors:
            raise InvalidCommandException("unknown language '%s'" %
                                          language_id)
        elif time_limit <= 0:
            raise InvalidCommandException('--time-limit must be >= 0')
        elif memory_limit <= 0:
            raise InvalidCommandException('--memory-limit must be >= 0')

        src = self.get_source(
            source_file) if source_file else self.open_editor(language_id)

        self.judge.submission_id_counter += 1
        self.judge.graded_submissions.append(
            (problem_id, language_id, src, time_limit, memory_limit))
        self.judge.begin_grading(self.judge.submission_id_counter,
                                 problem_id,
                                 language_id,
                                 src,
                                 time_limit,
                                 memory_limit,
                                 False,
                                 False,
                                 blocking=True)
Example #6
0
    def execute(self, line: str) -> None:
        args = self.arg_parser.parse_args(line)

        problem_id: str = args.problem_id
        language_id: Optional[str] = args.language_id
        time_limit: float = args.time_limit
        memory_limit: int = args.memory_limit
        source_file: Optional[str] = args.source_file

        if language_id not in executors:
            source_file = language_id
            language_id = None  # source file / language id optional

        if problem_id not in judgeenv.get_supported_problems():
            raise InvalidCommandException(f"unknown problem '{problem_id}'")
        elif not language_id:
            if source_file:
                filename, dot, ext = source_file.partition('.')
                if not ext:
                    raise InvalidCommandException('invalid file name')
                else:
                    # TODO: this should be a proper lookup elsewhere
                    ext = ext.upper()
                    language_id = {
                        'PY': 'PY2',
                        'CPP': 'CPP11',
                        'JAVA': 'JAVA8'
                    }.get(ext, ext)
            else:
                raise InvalidCommandException('no language is selected')
        elif language_id not in executors:
            raise InvalidCommandException(f"unknown language '{language_id}'")
        elif time_limit <= 0:
            raise InvalidCommandException('--time-limit must be >= 0')
        elif memory_limit <= 0:
            raise InvalidCommandException('--memory-limit must be >= 0')

        assert language_id is not None
        src = self.get_source(
            source_file) if source_file else self.open_editor(language_id)

        self.judge.submission_id_counter += 1
        self.judge.graded_submissions.append(
            (problem_id, language_id, src, time_limit, memory_limit))
        try:
            self.judge.begin_grading(
                Submission(self.judge.submission_id_counter, problem_id,
                           language_id, src, time_limit, memory_limit, False,
                           {}),
                blocking=True,
                report=print,
            )
        except KeyboardInterrupt:
            self.judge.abort_grading()
Example #7
0
 def update_problems(self):
     """
     Pushes current problem set to server.
     """
     self._problem_is_stale = True
     if not self._updating_problem:
         # If a signal is received here, there is still a race.
         # But how probable is that?
         self._updating_problem = True
         while self._problem_is_stale:
             self._problem_is_stale = False
             self.packet_manager.supported_problems_packet(
                 get_supported_problems())
         self._updating_problem = False
Example #8
0
    def execute(self, line):
        _args = self.arg_parser.parse_args(line)
        all_problems = judgeenv.get_supported_problems()

        if _args.filter:
            r = re.compile(_args.filter)
            all_problems = filter(lambda x: r.match(x[0]) is not None, all_problems)

        if _args.limit:
            all_problems = all_problems[:_args.limit]

        problems = iter(map(itemgetter(0), all_problems))
        max_len = max(len(p[0]) for p in all_problems)
        for row in izip_longest(*[problems] * 4, fillvalue=''):
            print ' '.join(('%*s' % (-max_len, row[i])) for i in xrange(4))
        print
Example #9
0
    def execute(self, line):
        _args = self.arg_parser.parse_args(line)
        all_problems = judgeenv.get_supported_problems()

        if _args.filter:
            r = re.compile(_args.filter)
            all_problems = filter(lambda x: r.match(x[0]) is not None,
                                  all_problems)

        if _args.limit:
            all_problems = all_problems[:_args.limit]

        problems = iter(map(itemgetter(0), all_problems))
        max_len = max(len(p[0]) for p in all_problems)
        for row in izip_longest(*[problems] * 4, fillvalue=''):
            print ' '.join(('%*s' % (-max_len, row[i])) for i in xrange(4))
        print
Example #10
0
def add_submission(body):
    judge = get_judge()
    body = connexion.request.get_json()
    problem_id = body['problemId']
    language_id = body['languageId']
    time_limit = body['timeLimit']
    memory_limit = body['memoryLimit']
    source = body['sourceCode']

    if problem_id not in map(itemgetter(0), judgeenv.get_supported_problems()):
        return jsonify({
            'error': "unknown problem %s" % problem_id
        }), 405
    
    if language_id not in executors.executors:
        return jsonify({'error': "unknown languae %s" % language_id}), 405

    if time_limit <= 0:
        return jsonify({'error': "timeLimit must be >= 0"}), 405

    if memory_limit <= 0:
        return jsonify({'error': "memoryLimit must be >= 0"}), 405

    submission_id = judge.next_submission_id
    
    judge.graded_submissions.append({
        "submissionId":  submission_id,
        "problemId": problem_id,
        "languageId": language_id,
        "sourceCode": source,
        "timeLimit": time_limit,
        "memoryLimit": memory_limit,
        "compileError": [],
        "compileMessage": [],
        "testCaseResults": [],
        "internalError":[]
    })

    source = b64decode(source).decode('utf-8')
    print(source)
    judge.begin_grading(submission_id, problem_id, language_id, source, time_limit,
                        memory_limit, False, False, blocking=True)

    judge.next_submission_id += 1
    
    return jsonify(judge.graded_submissions[submission_id]), 200
Example #11
0
    def execute(self, line: str) -> None:
        args = self.arg_parser.parse_args(line)

        problem_id: str = args.problem_id
        language_id: Optional[str] = args.language_id
        time_limit: float = args.time_limit
        memory_limit: int = args.memory_limit
        source_file: Optional[str] = args.source_file

        if language_id not in executors.executors:
            source_file = language_id
            language_id = None  # source file / language id optional

        if problem_id not in judgeenv.get_supported_problems():
            raise InvalidCommandException(f"unknown problem '{problem_id}'")
        elif not language_id:
            if source_file:
                language_id = executors.from_filename(
                    source_file).Executor.name
            else:
                raise InvalidCommandException('no language is selected')
        elif language_id not in executors.executors:
            raise InvalidCommandException(f"unknown language '{language_id}'")
        elif time_limit <= 0:
            raise InvalidCommandException('--time-limit must be >= 0')
        elif memory_limit <= 0:
            raise InvalidCommandException('--memory-limit must be >= 0')

        assert language_id is not None
        src = self.get_source(
            source_file) if source_file else self.open_editor(language_id)

        self.judge.submission_id_counter += 1
        self.judge.graded_submissions.append(
            (problem_id, language_id, src, time_limit, memory_limit))
        try:
            self.judge.begin_grading(
                Submission(self.judge.submission_id_counter, problem_id,
                           language_id, src, time_limit, memory_limit, False,
                           {}),
                blocking=True,
                report=print,
            )
        except KeyboardInterrupt:
            self.judge.abort_grading()
Example #12
0
    def _connect(self):
        problems = get_supported_problems()
        versions = get_runtime_versions()

        log.info('Opening connection to: [%s]:%s', self.host, self.port)
        self.conn = socket.create_connection((self.host, self.port), timeout=5)
        self.conn.settimeout(300)
        self.conn.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)

        if self.ssl_context:
            log.info('Starting TLS on: [%s]:%s', self.host, self.port)
            self.conn = self.ssl_context.wrap_socket(self.conn, server_hostname=self.host)

        log.info('Starting handshake with: [%s]:%s', self.host, self.port)
        self.input = self.conn.makefile('r')
        self.output = self.conn.makefile('w', 0)
        self.handshake(problems, versions, self.name, self.key)
        log.info('Judge "%s" online: [%s]:%s', self.name, self.host, self.port)
Example #13
0
    def test_all(self):
        total_fails = 0

        for problem, _ in get_supported_problems():
            if self.problem_regex is not None and not self.problem_regex.match(problem):
                continue
            root = get_problem_root(problem)
            test_dir = os.path.join(root, 'tests')
            if os.path.isdir(test_dir):
                fails = self.test_problem(problem, test_dir)
                if fails:
                    self.output(ansi_style('Problem #ansi[%s](cyan|bold) #ansi[failed %d case(s)](red|bold).') %
                                (problem, fails))
                else:
                    self.output(ansi_style('Problem #ansi[%s](cyan|bold) passed with flying colours.') % problem)
                self.output()
                total_fails += fails

        return total_fails
Example #14
0
File: submit.py Project: DMOJ/judge
    def execute(self, line):
        args = self.arg_parser.parse_args(line)

        problem_id = args.problem_id
        language_id = args.language_id
        time_limit = args.time_limit
        memory_limit = args.memory_limit
        source_file = args.source_file

        if language_id not in executors:
            source_file = language_id
            language_id = None  # source file / language id optional

        if problem_id not in map(itemgetter(0), judgeenv.get_supported_problems()):
            raise InvalidCommandException("unknown problem '%s'" % problem_id)
        elif not language_id:
            if source_file:
                filename, dot, ext = source_file.partition('.')
                if not ext:
                    raise InvalidCommandException('invalid file name')
                else:
                    # TODO: this should be a proper lookup elsewhere
                    ext = ext.upper()
                    language_id = {
                        'PY': 'PY2',
                        'CPP': 'CPP11',
                        'JAVA': 'JAVA8'
                    }.get(ext, ext)
            else:
                raise InvalidCommandException("no language is selected")
        elif language_id not in executors:
            raise InvalidCommandException("unknown language '%s'" % language_id)
        elif time_limit <= 0:
            raise InvalidCommandException('--time-limit must be >= 0')
        elif memory_limit <= 0:
            raise InvalidCommandException('--memory-limit must be >= 0')

        src = self.get_source(source_file) if source_file else self.open_editor(language_id)

        self.judge.submission_id_counter += 1
        self.judge.graded_submissions.append((problem_id, language_id, src, time_limit, memory_limit))
        self.judge.begin_grading(self.judge.submission_id_counter, problem_id, language_id, src, time_limit,
                                 memory_limit, False, False, blocking=True)
Example #15
0
    def test_all(self):
        total_fails = 0

        for problem, _ in get_supported_problems():
            if self.problem_regex is not None and not self.problem_regex.match(problem):
                continue
            root = get_problem_root(problem)
            test_dir = os.path.join(root, 'tests')
            if os.path.isdir(test_dir):
                fails = self.test_problem(problem, test_dir)
                if fails:
                    self.output(ansi_style('Problem #ansi[%s](cyan|bold) #ansi[failed %d case(s)](red|bold).') %
                                (problem, fails))
                else:
                    self.output(ansi_style('Problem #ansi[%s](cyan|bold) passed with flying colours.') % problem)
                self.output()
                total_fails += fails

        return total_fails
Example #16
0
File: judge.py Project: DMOJ/judge
    def _updater_thread(self):
        log = logging.getLogger('dmoj.updater')
        while True:
            self.updater_signal.wait()
            self.updater_signal.clear()
            if self.updater_exit:
                return

            # Prevent problem updates while grading.
            # Capture the value so it can't change.
            thread = self.current_submission_thread
            if thread:
                thread.join()

            try:
                clear_problem_dirs_cache()
                self.packet_manager.supported_problems_packet(get_supported_problems())
            except Exception:
                log.exception('Failed to update problems.')
Example #17
0
    def _updater_thread(self):
        log = logging.getLogger('dmoj.updater')
        while True:
            self.updater_signal.wait()
            self.updater_signal.clear()
            if self.updater_exit:
                return

            # Prevent problem updates while grading.
            # Capture the value so it can't change.
            thread = self.current_submission_thread
            if thread:
                thread.join()

            try:
                clear_problem_dirs_cache()
                self.packet_manager.supported_problems_packet(get_supported_problems())
            except Exception:
                log.exception('Failed to update problems.')
Example #18
0
    def _updater_thread(self) -> None:
        log = logging.getLogger('dmoj.updater')
        while True:
            self.updater_signal.wait()
            self.updater_signal.clear()
            if self.updater_exit:
                return

            # Prevent problem updates while grading.
            # Capture the value so it can't change.
            # FIXME(tbrindus): this is broken.
            # thread = sub_judge_thread
            # if thread:
            #    thread.join()

            try:
                clear_problem_dirs_cache()
                self.packet_manager.supported_problems_packet(get_supported_problems())
            except Exception:
                log.exception('Failed to update problems.')
Example #19
0
    def execute(self, line):
        global submission_id_counter, graded_submissions

        args = self.arg_parser.parse_args(line)

        submission_id_counter += 1
        try:
            id, lang, src, tl, ml = graded_submissions[args.submission_id - 1]
        except IndexError:
            print ansi_style("#ansi[invalid submission '%d'](red|bold)\n" %
                             (args.submission_id - 1))
            return

        id = args.problem or id
        lang = args.language or lang
        tl = args.time_limit or tl
        ml = args.memory_limit or ml

        err = None
        if id not in map(itemgetter(0), judgeenv.get_supported_problems()):
            err = "unknown problem '%s'" % id
        elif lang not in executors:
            err = "unknown language '%s'" % lang
        elif tl <= 0:
            err = '--time-limit must be >= 0'
        elif ml <= 0:
            err = '--memory-limit must be >= 0'
        if err:
            print ansi_style('#ansi[%s](red|bold)\n' % err)
            return

        graded_submissions.append((id, lang, src, tl, ml))
        self.judge.begin_grading(submission_id_counter,
                                 id,
                                 lang,
                                 src,
                                 tl,
                                 ml,
                                 False,
                                 False,
                                 blocking=True)
Example #20
0
    def execute(self, line):
        args = self.arg_parser.parse_args(line)

        problem_ids = args.problem_ids
        supported_problems = set(get_supported_problems())

        unknown_problems = ', '.join(
            map(
                lambda x: "'%s'" % x,
                filter(lambda problem_id: problem_id not in supported_problems,
                       problem_ids)))
        if unknown_problems:
            raise InvalidCommandException("unknown problem(s) %s" %
                                          unknown_problems)

        tester = ProblemTester()
        total_fails = 0
        for problem_id in problem_ids:
            fails = tester.test_problem(problem_id)
            if fails:
                print_ansi(
                    'Problem #ansi[%s](cyan|bold) #ansi[failed %d case(s)](red|bold).'
                    % (problem_id, fails))
            else:
                print_ansi(
                    'Problem #ansi[%s](cyan|bold) passed with flying colours.'
                    % problem_id)
            print()
            total_fails += fails

        print()
        print('Test complete.')
        if fails:
            print_ansi('#ansi[A total of %d test(s) failed](red|bold)' % fails)
        else:
            print_ansi('#ansi[All tests passed.](green|bold)')

        return fails
Example #21
0
    def execute(self, line):
        _args = self.arg_parser.parse_args(line)

        if _args.limit is not None and _args.limit <= 0:
            raise InvalidCommandException('--limit must be >= 0')

        all_problems = judgeenv.get_supported_problems()

        if _args.filter:
            r = re.compile(_args.filter)
            all_problems = list(
                filter(lambda p: r.match(p) is not None, all_problems))

        if _args.limit:
            all_problems = all_problems[:_args.limit]

        if len(all_problems):
            max_len = max(len(p) for p in all_problems)
            for row in zip_longest(*[iter(all_problems)] * 4, fillvalue=''):
                print(' '.join(('%*s' % (-max_len, row[i])) for i in range(4)))
            print()
        else:
            raise InvalidCommandException('No problems matching filter found.')
Example #22
0
    def execute(self, line):
        _args = self.arg_parser.parse_args(line)

        if _args.limit is not None and _args.limit <= 0:
            raise InvalidCommandException('--limit must be >= 0')

        all_problems = judgeenv.get_supported_problems()

        if _args.filter:
            r = re.compile(_args.filter)
            all_problems = filter(lambda x: r.match(x[0]) is not None, all_problems)

        if _args.limit:
            all_problems = all_problems[:_args.limit]

        if len(all_problems):
            problems = iter(map(itemgetter(0), all_problems))
            max_len = max(len(p[0]) for p in all_problems)
            for row in zip_longest(*[problems] * 4, fillvalue=''):
                print(' '.join(('%*s' % (-max_len, row[i])) for i in range(4)))
            print()
        else:
            raise InvalidCommandException('No problems matching filter found.')
Example #23
0
    def execute(self, line):
        global submission_id_counter, graded_submissions

        args = self.arg_parser.parse_args(line)

        problem_id = args.problem_id
        language_id = args.language_id
        time_limit = args.time_limit
        memory_limit = args.memory_limit

        err = None
        if problem_id not in map(itemgetter(0), judgeenv.get_supported_problems()):
            err = "unknown problem '%s'" % problem_id
        elif language_id not in executors:
            err = "unknown language '%s'" % language_id
        elif time_limit <= 0:
            err = '--time-limit must be >= 0'
        elif memory_limit <= 0:
            err = '--memory-limit must be >= 0'
        if err:
            print ansi_style('#ansi[%s](red|bold)\n' % err)
            return

        src = []
        try:
            while True:
                s = raw_input()
                if s.strip() == ':q':
                    raise EOFError
                src.append(s)
        except EOFError:  # Ctrl+D
            src = '\n'.join(src)

        submission_id_counter += 1
        graded_submissions.append((problem_id, language_id, src, time_limit, memory_limit))
        self.judge.begin_grading(submission_id_counter, problem_id, language_id, src, time_limit,
                                 memory_limit, False, blocking=True)
Example #24
0
    def execute(self, line: str) -> int:
        args = self.arg_parser.parse_args(line)

        problem_ids = args.problem_ids
        supported_problems = set(get_supported_problems())

        unknown_problems = ', '.join(f"'{i}'" for i in problem_ids
                                     if i not in supported_problems)
        if unknown_problems:
            raise InvalidCommandException(
                f'unknown problem(s) {unknown_problems}')

        tester = ProblemTester()
        total_fails = 0
        for problem_id in problem_ids:
            fails = tester.run_problem_tests(problem_id)
            if fails:
                print_ansi(
                    f'Problem #ansi[{problem_id}](cyan|bold) #ansi[failed {fails} case(s)](red|bold).'
                )
            else:
                print_ansi(
                    f'Problem #ansi[{problem_id}](cyan|bold) passed with flying colours.'
                )
            print()
            total_fails += fails

        print()
        print('Test complete.')
        if total_fails:
            print_ansi(
                f'#ansi[A total of {total_fails} test(s) failed](red|bold)')
        else:
            print_ansi('#ansi[All tests passed.](green|bold)')

        return total_fails
Example #25
0
    def execute(self, line):
        _args = self.arg_parser.parse_args(line)

        if _args.limit is not None and _args.limit <= 0:
            print ansi_style("#ansi[--limit must be >= 0](red|bold)\n")
            return

        all_problems = judgeenv.get_supported_problems()

        if _args.filter:
            r = re.compile(_args.filter)
            all_problems = filter(lambda x: r.match(x[0]) is not None, all_problems)

        if _args.limit:
            all_problems = all_problems[:_args.limit]

        if len(all_problems):
            problems = iter(map(itemgetter(0), all_problems))
            max_len = max(len(p[0]) for p in all_problems)
            for row in izip_longest(*[problems] * 4, fillvalue=''):
                print ' '.join(('%*s' % (-max_len, row[i])) for i in xrange(4))
        else:
            print ansi_style("#ansi[No problems matching filter found.](red|bold)")
        print
Example #26
0
    def execute(self, line):
        args = self.arg_parser.parse_args(line)

        id, lang, src, tl, ml = self.get_submission_data(args.submission_id)

        id = args.problem or id
        lang = args.language or lang
        tl = args.time_limit or tl
        ml = args.memory_limit or ml

        if id not in map(itemgetter(0), judgeenv.get_supported_problems()):
            raise InvalidCommandException("unknown problem '%s'" % id)
        elif lang not in executors:
            raise InvalidCommandException("unknown language '%s'" % lang)
        elif tl <= 0:
            raise InvalidCommandException('--time-limit must be >= 0')
        elif ml <= 0:
            raise InvalidCommandException('--memory-limit must be >= 0')

        src = self.open_editor(lang, src)

        self.judge.submission_id_counter += 1
        self.judge.graded_submissions.append((id, lang, src, tl, ml))
        self.judge.begin_grading(self.judge.submission_id_counter, id, lang, src, tl, ml, False, False, blocking=True)
Example #27
0
    def execute(self, line):
        _args = self.arg_parser.parse_args(line)

        if _args.limit is not None and _args.limit <= 0:
            print ansi_style("#ansi[--limit must be >= 0](red|bold)\n")
            return

        all_problems = judgeenv.get_supported_problems()

        if _args.filter:
            r = re.compile(_args.filter)
            all_problems = filter(lambda x: r.match(x[0]) is not None, all_problems)

        if _args.limit:
            all_problems = all_problems[:_args.limit]

        if len(all_problems):
            problems = iter(map(itemgetter(0), all_problems))
            max_len = max(len(p[0]) for p in all_problems)
            for row in izip_longest(*[problems] * 4, fillvalue=''):
                print ' '.join(('%*s' % (-max_len, row[i])) for i in xrange(4))
        else:
            print ansi_style("#ansi[No problems matching filter found.](red|bold)")
        print
Example #28
0
 def _connect(self):
     self.conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.conn.connect((self.host, self.port))
     self.input = self.conn.makefile('r')
     self.output = self.conn.makefile('w', 0)
     self.handshake(get_supported_problems(), self.name, self.key)
Example #29
0
 def update_problems(self):
     """
     Pushes current problem set to server.
     """
     self.packet_manager.supported_problems_packet(get_supported_problems())
Example #30
0
 def update_problems(self):
     """
     Pushes current problem set to server.
     """
     self.packet_manager.supported_problems_packet(get_supported_problems())