Skip to content

Commit

Permalink
Add support for pdf-statement and solution
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaohuba committed Jun 28, 2024
1 parent cb7adb1 commit 97c9570
Showing 1 changed file with 42 additions and 8 deletions.
50 changes: 42 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
parser.add_argument("filename", type=str, help="Lemon work path")
parser.add_argument("-S", "--silent", help="Silent mode", action="store_true")
parser.add_argument("-A", "--attach", help="Attach statement", action="store_true")
parser.add_argument("-O", "--solution", help="Attach solution", action="store_true")
parser.add_argument("-Z", "--zip", help="Auto create zipfile", action="store_true")
parser.add_argument(
"--task", nargs="?", default="*", help="Parse specific task (* for all)"
Expand All @@ -23,6 +24,7 @@
lemonDir = os.path.abspath(args.filename)
silent = args.silent
attach_statement = args.attach
attach_sol = args.solution
parse_task = args.task
create_zip = args.zip
cdfPath = utils.getCDFPath(lemonDir)
Expand Down Expand Up @@ -132,22 +134,54 @@
else:
print("WARNING: This task has unsupported spj.")
print("You may need to edit it manually.")
conf += f"use_builtin_judger on\n"
if task["taskType"] != 0:
print("WARNING: Unsupported task type.")
print("You may need to configure it manually.")
confFile = open(os.path.join("to_uoj", taskname, "problem.conf"), "w")
confFile.write(conf)
confFile.close()

if attach_statement:
statement_path = os.path.join("down", "statement.pdf")
down_path = os.path.join("to_uoj", taskname, "download")
main_path = os.path.join("to_uoj", taskname)
os.mkdir(down_path)
try:
print("INFO: Copying", fr, "->", to)
print(
"INFO: Copying statement",
statement_path,
"->",
f"{down_path}/statement.pdf",
)
shutil.copy2(statement_path, down_path)
print(
"INFO: Copying statement",
statement_path,
"->",
f"{main_path}/statement.pdf",
)
shutil.copy2(statement_path, main_path)
except Exception as exp:
print(f"ERROR: Failed to attach statement!\nException is {exp}")
conf += f"use_pdf_statement on"

if attach_sol:
sol_path = "solution.pdf"
main_path = os.path.join("to_uoj", taskname)
try:
print(
"INFO: Copying statement",
sol_path,
"->",
f"{main_path}/solution.pdf",
)
shutil.copy2(sol_path, main_path)
except Exception as exp:
print(f"ERROR: Failed to attach statement!\nException is {exp}")
conf += f"show_solution on"

conf += f"use_builtin_judger on\n"
if task["taskType"] != 0:
print("WARNING: Unsupported task type.")
print("You may need to configure it manually.")
confFile = open(os.path.join("to_uoj", taskname, "problem.conf"), "w")
confFile.write(conf)
confFile.close()

if create_zip:
print(f"INFO: creating zipfile for task `{taskname}`...", end=" ")
sys.stdout.flush()
Expand Down

0 comments on commit 97c9570

Please sign in to comment.