Skip to content

Commit

Permalink
Enchance spj support.
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaohuba committed Jul 16, 2024
1 parent 6eceb67 commit 7f3af6d
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
29 changes: 17 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
print("Exiting...")
exit(1)

print(f"INFO: Load .cdf file: {cdfPath}\n")
print(f"INFO: Loaded .cdf file: {cdfPath}\n")

with open(cdfPath, "r", encoding="utf-8") as cdf:
json_obj = json.load(cdf)
Expand Down Expand Up @@ -118,23 +118,28 @@
# Hack: universaloj doesn't support float TL. Round to integer instead.
conf += f"time_limit {round(tl / 1000)}\n"
conf += f"memory_limit {ml}\n"
if len(task["specialJudge"]) == 0:
if task["specialJudge"] in ("", "wcmp"):
conf += f"use_builtin_checker wcmp\n"
if not silent:
print(f"INFO: Using `wcmp` for task {taskname}.")
else:
(state, text) = utils.parseSPJ(os.path.join(lemonDir, "data", taskname))
# print(f"LOG: {os.path.join(lemonDir, 'data', taskname)}")
if state == 0:
spj_name = (
task["specialJudge"].replace(".exe", ".cpp").replace(".bin", ".cpp")
)
if not spj_name.endswith(".cpp"):
spj_name += ".cpp"
try:
if not silent:
print(f"INFO: Parsing spj for task {taskname}...")
print(f"INFO: Parsing spj {spj_name} for task {taskname}...")
text = utils.parseSPJ(os.path.join(lemonDir, "data", spj_name))
except Exception as err:
print(f"WARNING: Exception caught: {err}")
print("WARNING: This task has unsupported spj.")
print("You may need to edit it manually.")
else:
spjFile = open(os.path.join("to_uoj", taskname, "chk.cpp"), "w")
spjFile.write(text)
spjFile.close()
else:
print("WARNING: This task has unsupported spj.")
print("You may need to edit it manually.")

if attach_statement:
statement_path = os.path.join("down", "statement.pdf")
down_path = os.path.join("to_uoj", taskname, "download")
Expand Down Expand Up @@ -164,7 +169,7 @@
main_path = os.path.join("to_uoj", taskname)
try:
print(
"INFO: Copying statement",
"INFO: Copying solution",
sol_path,
"->",
f"{main_path}/solution.pdf",
Expand All @@ -183,7 +188,7 @@
confFile.close()

if create_zip:
print(f"INFO: creating zipfile for task `{taskname}`...", end=" ")
print(f"INFO: Creating zipfile for task `{taskname}`...", end=" ")
sys.stdout.flush()
utils.zipProblem(os.path.join("to_uoj", taskname))
print(f"done.")
Expand Down
27 changes: 11 additions & 16 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,17 @@ def parsePath(pth):
return final


def parseSPJ(pth):
files = os.listdir(pth)
for file in files:
# print(f"{file}")
if file in ("chk.cpp", "checker.cpp"):
with open(os.path.join(pth, file), "r") as spj:
content = spj.read()
content = content.replace("testlib_for_lemon.h", "testlib.h")
content = content.replace("testlib_for_lemons.h", "testlib.h")
content = content.replace("registerLemonChecker", "registerTestlibCmd")
# print(content)
if content.find("testlib.h") == -1:
return (-1, "")
else:
return (0, content)
return (-1, "")
def parseSPJ(file):
with open(os.path.join(file), "r") as spj:
content = spj.read()
content = content.replace("testlib_for_lemon.h", "testlib.h")
content = content.replace("testlib_for_lemons.h", "testlib.h")
content = content.replace("registerLemonChecker", "registerTestlibCmd")
# print(content)
if content.find("testlib.h") == -1:
raise Exception("SPJ must be written with testlib.h.")
else:
return content


def isDependence(name):
Expand Down

0 comments on commit 7f3af6d

Please sign in to comment.