diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 383e65c..0f1b27f 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -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') diff --git a/main.py b/main.py index fa10aab..b3ee0e5 100644 --- a/main.py +++ b/main.py @@ -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 """ @@ -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) @@ -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 @@ -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 @@ -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" @@ -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() diff --git a/utils.py b/utils.py index 7801643..0d851f9 100644 --- a/utils.py +++ b/utils.py @@ -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: @@ -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") @@ -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()