示例#1
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)
示例#2
0
 def open_editor(self, lang, src=b''):
     file_suffix = executors[lang].Executor.ext
     editor = os.environ.get('EDITOR')
     if editor:
         with tempfile.NamedTemporaryFile(suffix=file_suffix) as temp:
             temp.write(src)
             temp.flush()
             subprocess.call([editor, temp.name])
             temp.seek(0)
             src = temp.read()
     else:
         print(
             ansi_style(
                 '#ansi[$EDITOR not set, falling back to stdin](yellow)\n'))
         src = []
         try:
             while True:
                 s = input()
                 if s.strip() == ':q':
                     raise EOFError
                 src.append(s)
         except EOFError:  # Ctrl+D
             src = '\n'.join(src)
         except Exception as io:
             raise InvalidCommandException(str(io))
     return src
示例#3
0
    def get_submission_data(self, submission_id):
        # don't wrap around
        if submission_id > 0:
            try:
                return self.judge.graded_submissions[submission_id - 1]
            except IndexError:
                pass

        raise InvalidCommandException("invalid submission '%d'" % submission_id)
示例#4
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")

        submissions = self.judge.graded_submissions if not args.limit else self.judge.graded_submissions[:args
                                                                                                         .
                                                                                                         limit]

        for i, (problem, lang, src, tl, ml) in enumerate(submissions):
            print ansi_style('#ansi[%s](yellow)/#ansi[%s](green) in %s' %
                             (problem, i + 1, lang))
        print
示例#5
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 izip_longest(*[problems] * 4, fillvalue=''):
                print ' '.join(('%*s' % (-max_len, row[i])) for i in xrange(4))
            print
        else:
            raise InvalidCommandException('No problems matching filter found.')
示例#6
0
    def execute(self, line):
        print("Farhad -------- Execute started...............")
        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)
示例#7
0
 def get_source(self, source_file):
     try:
         with open(os.path.realpath(source_file)) as f:
             return f.read()
     except Exception as io:
         raise InvalidCommandException(str(io))