From 4e276a74599d77b2a29bc4c3f18b078716db75c2 Mon Sep 17 00:00:00 2001 From: Maarten Sijm <9739541+mpsijm@users.noreply.github.com> Date: Sat, 16 Mar 2024 15:06:08 +0100 Subject: [PATCH] [export] Make sure that update_problems_yaml uses a single language Also slightly refactor `bt zip` and `bt samplezip` to use the same force_single_language function --- bin/export.py | 37 ++++++++++++++++++++++++++----------- bin/tools.py | 25 +++++-------------------- 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/bin/export.py b/bin/export.py index a7d3d6c7..99bfb9bf 100644 --- a/bin/export.py +++ b/bin/export.py @@ -36,6 +36,17 @@ def revert(): return revert +def force_single_language(problems): + if config.args.language: + statement_language = config.args.language + else: + all_languages = set.union(*(set(p.statement_languages) for p in problems)) + if len(all_languages) > 1: + fatal('Multiple languages found, please specify one with --language') + statement_language = all_languages.pop() + return statement_language + + # Write any .lang.pdf files to .pdf. def remove_language_suffix(fname, statement_language): if not statement_language: @@ -46,7 +57,10 @@ def remove_language_suffix(fname, statement_language): return out -def build_samples_zip(problems, statement_language): +def build_samples_zip(problems): + # Add contest PDF for only one language to the zip file + statement_language = force_single_language(problems) + zf = zipfile.ZipFile( 'samples.zip', mode="w", compression=zipfile.ZIP_DEFLATED, allowZip64=False ) @@ -101,9 +115,12 @@ def build_samples_zip(problems, statement_language): print("Wrote zip to samples.zip", file=sys.stderr) -def build_problem_zip(problem, output, statement_language): +def build_problem_zip(problem, output): """Make DOMjudge ZIP file for specified problem.""" + # Add problem PDF for only one language to the zip file (note that Kattis export does not include PDF) + statement_language = None if config.args.kattis else force_single_language([problem]) + deprecated = [ # may be removed at some point. 'domjudge-problem.ini', ] @@ -335,25 +352,23 @@ def update_problems_yaml(problems, colors=None): path = Path('problems.yaml') data = path.is_file() and read_yaml(path) or [] + # DOMjudge does not yet support multilingual problems.yaml files. + statement_language = force_single_language(problems) + change = False for problem in problems: found = False - default_language = ( - 'en' - if 'en' in problem.statement_languages - else next(iter(problem.statement_languages), None) - ) - problem_name = ( - problem.settings.name and default_language and problem.settings.name[default_language] - ) + problem_name = problem.settings.name + if isinstance(problem_name, dict): + problem_name = problem_name[statement_language] for d in data: if d['id'] == problem.name: found = True if problem_name != d.get('name'): change = True - d['name'] = problem.settings.name + d['name'] = problem_name if 'rgb' not in d: change = True diff --git a/bin/tools.py b/bin/tools.py index 1772b423..287e6533 100755 --- a/bin/tools.py +++ b/bin/tools.py @@ -828,10 +828,7 @@ def run_parsed_arguments(args): return if action == 'samplezip': - # Add contest PDF for only one language to the zip file - statement_language = force_single_language(problems) - - export.build_samples_zip(problems, statement_language) + export.build_samples_zip(problems) return if action == 'rename_problem': @@ -926,11 +923,10 @@ def run_parsed_arguments(args): config.args = old_args if not config.args.kattis: + # Make sure that all problems use the same language for the PDFs + export.force_single_language(problems) + success &= latex.build_problem_pdfs(problem) - # Add problem PDF for only one language to the zip file - statement_language = force_single_language(problems) - else: - statement_language = None if not config.args.force: success &= problem.validate_data(validate.Mode.INPUT, constraints={}) @@ -938,7 +934,7 @@ def run_parsed_arguments(args): # Write to problemname.zip, where we strip all non-alphanumeric from the # problem directory name. - success &= export.build_problem_zip(problem, output, statement_language) + success &= export.build_problem_zip(problem, output) if len(problems) > 1: print(file=sys.stderr) @@ -990,17 +986,6 @@ def run_parsed_arguments(args): sys.exit(1) -def force_single_language(problems): - if config.args.language: - statement_language = config.args.language - else: - all_languages = set.union(*(set(p.statement_languages) for p in problems)) - if len(all_languages) > 1: - fatal('Multiple languages found, please specify one with --language') - statement_language = all_languages.pop() - return statement_language - - def read_personal_config(): args = {}