Skip to content

Commit

Permalink
Update workflow & feat
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaohuba committed May 13, 2024
1 parent f613f67 commit cb7adb1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
pylint --exit-zero $(git ls-files '*.py')
25 changes: 14 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
Parse `.cdf` file of [lemonlime](https://github.com/Project-LemonLime/Project_LemonLime), and generate uoj-format `problem.conf`!
Parse `.cdf` file of [lemonlime](https://github.com/Project-LemonLime/Project_LemonLime),
and generate uoj-format `problem.conf`!
Author: Xiaohuba
"""

Expand All @@ -26,7 +27,7 @@
create_zip = args.zip
cdfPath = utils.getCDFPath(lemonDir)

if cdfPath == None:
if cdfPath is None:
print("ERROR: No .cdf file found!")
print("Exiting...")
exit(1)
Expand Down Expand Up @@ -56,7 +57,7 @@
testcases = task["testCases"]
conf = f"# auto-generated-conf-file-by-lemon-parser-{__version__}\n"
cnt = 0
id = 0
tc_id = 0
score = 0
tl = 0
ml = 0
Expand All @@ -66,11 +67,11 @@
conf += f"output_suf out\n"
conf += f"n_subtasks {len(testcases)}\n"
for case in testcases:
id += 1
tc_id += 1
score += case["fullScore"]
# Hack: inputFiles may contain dependence flags; use outputFiles instead
conf += f"subtask_end_{id} {cnt + len(case['outputFiles'])}\n"
conf += f"subtask_score_{id} {case['fullScore']}\n"
conf += f"subtask_end_{tc_id} {cnt + len(case['outputFiles'])}\n"
conf += f"subtask_score_{tc_id} {case['fullScore']}\n"
tl = max(tl, case["timeLimit"])
ml = max(ml, case["memoryLimit"])
caseid = 0
Expand Down Expand Up @@ -104,15 +105,16 @@
shutil.copy2(fr, to)
cnt += caseid
if len(dep) > 0:
conf += f"subtask_dependence_{id} many\n"
conf += f"subtask_dependence_{tc_id} many\n"
dep_cnt = 0
for depd in dep:
dep_cnt += 1
conf += f"subtask_dependence_{id}_{dep_cnt} {depd}\n"
conf += f"subtask_dependence_{tc_id}_{dep_cnt} {depd}\n"
conf += f"n_tests {cnt}\n"
conf += f"n_ex_tests 0\n"
conf += f"n_sample_tests 0\n"
conf += f"time_limit {round(tl / 1000)}\n" # Hack: universaloj doesn't support float TL. Round to integer instead.
# 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:
conf += f"use_builtin_checker wcmp\n"
Expand All @@ -138,13 +140,14 @@
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")
os.mkdir(down_path)
try:
shutil.copy2(os.path.join("down", "statement.pdf"), down_path)
print("INFO: Copying", fr, "->", to)
shutil.copy2(statement_path, down_path)
except Exception as exp:
print(f"ERROR: Failed to attach statement!\nException is {exp}")
attach_statement = False
if create_zip:
print(f"INFO: creating zipfile for task `{taskname}`...", end=" ")
sys.stdout.flush()
Expand Down
6 changes: 3 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def parsePath(pth):
cur = ""
final = ""
for ch in pth:
if ch == "/" or ch == "\\":
if ch in ("/", "\\"):
if os_info == "Windows":
final += "\\" + cur
else:
Expand All @@ -31,7 +31,7 @@ def parseSPJ(pth):
files = os.listdir(pth)
for file in files:
# print(f"{file}")
if file == "chk.cpp" or file == "checker.cpp":
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")
Expand All @@ -57,7 +57,7 @@ def zipProblem(path):
cur = os.path.abspath(os.curdir)
zip_obj = zipfile.ZipFile(path + ".zip", "w", zipfile.ZIP_DEFLATED)
os.chdir(path)
for root, dirs, files in os.walk("."):
for root, _, files in os.walk("."):
for file in files:
zip_obj.write(os.path.join(root, file))
zip_obj.close()
Expand Down

0 comments on commit cb7adb1

Please sign in to comment.