Skip to content

Commit 7f6db82

Browse files
committed
make legacy export more robust
1 parent d99d699 commit 7f6db82

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

bin/export.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@ def add_testcase(in_file: Path) -> None:
235235
if config.args.legacy and languages:
236236
for type in PdfType:
237237
file = export_dir / type.path(languages[0], ".pdf").name
238-
file.rename(remove_language_pdf_suffix(file, languages[0]))
238+
if file.exists():
239+
file.rename(remove_language_pdf_suffix(file, languages[0]))
239240
else:
240241
for language in languages:
241242
for type in PdfType:
@@ -333,19 +334,20 @@ def add_testcase(in_file: Path) -> None:
333334
if (export_dir / "statement").exists():
334335
(export_dir / "statement").rename(export_dir / "problem_statement")
335336
for d in ["solution", "problem_slide"]:
336-
for f in list(util.glob(problem.path, f"{d}/*")):
337-
if f.is_file():
338-
out = Path("problem_statement") / f.relative_to(problem.path / d)
339-
if out.exists():
340-
message(
341-
f"Can not export {f.relative_to(problem.path)} as {out}",
342-
"Zip",
343-
output,
344-
color_type=MessageType.WARN,
345-
)
346-
else:
347-
add_file(out, f)
348-
shutil.rmtree(export_dir / d)
337+
if (export_dir / d).is_dir():
338+
for f in list(util.glob(problem.path, f"{d}/*")):
339+
if f.is_file():
340+
out = Path("problem_statement") / f.relative_to(problem.path / d)
341+
if out.exists():
342+
message(
343+
f"Can not export {f.relative_to(problem.path)} as {out}",
344+
"Zip",
345+
output,
346+
color_type=MessageType.WARN,
347+
)
348+
else:
349+
add_file(out, f)
350+
shutil.rmtree(export_dir / d)
349351

350352
# handle yaml updates
351353
yaml_path.unlink()

0 commit comments

Comments
 (0)