add cpp checker
This commit is contained in:
parent
f74f8b6e05
commit
e820697e60
6 changed files with 2859 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
import yaml
|
||||
from django.conf import settings
|
||||
|
@ -9,6 +10,10 @@ from django.core.files.storage import FileSystemStorage
|
|||
from django.urls import reverse
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
|
||||
VALIDATOR_TEMPLATE_PATH = 'validator_template/template.py'
|
||||
|
||||
|
||||
if os.altsep:
|
||||
def split_path_first(path, repath=re.compile('[%s]' % re.escape(os.sep + os.altsep))):
|
||||
return repath.split(path, 1)
|
||||
|
@ -63,17 +68,38 @@ class ProblemDataCompiler(object):
|
|||
raise ProblemDataError(_('Empty batches not allowed.'))
|
||||
cases.append(batch)
|
||||
|
||||
def make_checker_for_validator(case):
|
||||
checker_name = "cppvalidator.py"
|
||||
validator_path = split_path_first(case.custom_validator.name)
|
||||
|
||||
if len(validator_path) != 2:
|
||||
raise ProblemDataError(_('How did you corrupt the custom checker path?'))
|
||||
|
||||
checker = os.path.join(settings.DMOJ_PROBLEM_DATA_ROOT,
|
||||
validator_path[0],
|
||||
checker_name)
|
||||
|
||||
validator_name = validator_path[1]
|
||||
shutil.copy(VALIDATOR_TEMPLATE_PATH, checker)
|
||||
|
||||
# replace {{filecpp}} and {{problemid}} in checker file
|
||||
filedata = open(checker, 'r').read()
|
||||
filedata = filedata.replace('{{filecpp}}', "\'%s\'" % validator_name)
|
||||
filedata = filedata.replace('{{problemid}}', "\'%s\'" % validator_path[0])
|
||||
open(checker, 'w').write(filedata)
|
||||
|
||||
return checker_name
|
||||
|
||||
def make_checker(case):
|
||||
if (case.checker == 'custom'):
|
||||
custom_checker_path = split_path_first(case.custom_checker.name)
|
||||
if len(custom_checker_path) != 2:
|
||||
raise ProblemDataError(_('How did you corrupt the custom checker path?'))
|
||||
return(custom_checker_path[1])
|
||||
|
||||
if (case.checker == 'customval'):
|
||||
validator_path = split_path_first(case.custom_validator.name)
|
||||
if len(validator_path) != 2:
|
||||
raise ProblemDataError(_('How did you corrupt the custom checker path?'))
|
||||
return(validator_path[1])
|
||||
return make_checker_for_validator(case)
|
||||
|
||||
if case.checker_args:
|
||||
return {
|
||||
'name': case.checker,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue