From 0e8c2457e6a958fe1fc09e83c2f42f6b09eb8110 Mon Sep 17 00:00:00 2001 From: Federico Glaudo Date: Sat, 3 Dec 2022 15:27:12 -0500 Subject: [PATCH] Fixed domjudge id vs externalid --- README.md | 2 +- p2d/domjudge_api.py | 11 ++++++----- p2d/p2d.py | 1 + p2d/p2d_utils.py | 6 +++--- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 76b8e96..0b0b730 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ It must be a valid `yaml` file containing the following top-level keys: Some more keys are added (and managed) by `p2d` for caching purposes. Namely each problem will also contain the additional keys: `polygon_version`, `domjudge_local_version`, `domjudge_server_version`. These additional keys are managed by `p2d` and should not be created or modified by the user. In order to clear entirely the keys related to caching, use the flag `--clear-dir` (which will also clear the directory of the contest). -Moreover, each problem (after being uploaded for the first time on DOMjudge) is assigned a `domjudge_id` (which corresponds to the external ID of the problem in DOMjudge). +Moreover, each problem (after being uploaded for the first time on DOMjudge) is assigned a `domjudge_id` (a number) and a `domjudge_externalid` (which corresponds to the external ID of the problem in DOMjudge). In order to clear the DOMjudge IDs, use the flag `--clear-domjudge-ids`. See [this example](examples/config.yaml) for a valid `config.yaml` file. diff --git a/p2d/domjudge_api.py b/p2d/domjudge_api.py index 24fd34a..9a0160c 100644 --- a/p2d/domjudge_api.py +++ b/p2d/domjudge_api.py @@ -27,12 +27,12 @@ def call_domjudge_api(api_address, data, files, credentials): # Updates the problem on the server with the package_zip. # Returns true if the update was successful. -def update_problem_api(package_zip, problem_id, credentials): +def update_problem_api(package_zip, problem_domjudge_id, credentials): api_address = '/api/v4/contests/%s/problems' % credentials['contest_id'] with open(package_zip, 'rb') as f: res = call_domjudge_api(api_address, - {'problem': problem_id}, + {'problem': problem_domjudge_id}, {'zip': (package_zip, f)}, credentials) @@ -45,8 +45,8 @@ def update_problem_api(package_zip, problem_id, credentials): return True # Adds an "empty" problem to a contest. -# Returns true if the problem was successfully added. In such case, it set -# the 'domjudge_id' of the problem. +# Returns true if the problem was successfully added. In such case, it sets +# the 'domjudge_id' and 'domjudge_externalid' of the problem. # credentials is a dictionary with keys contest_id, server, username, password. def add_problem_to_contest_api(problem, credentials): api_address = '/api/v4/contests/%s/problems/add-data' % credentials['contest_id'] @@ -70,6 +70,7 @@ def add_problem_to_contest_api(problem, credentials): logging.error('Error adding the problem to the contest: %s.' % res.json()) return False - problem['domjudge_id'] = externalid + problem['domjudge_id'] = res.json()[0] + problem['domjudge_externalid'] = externalid return True diff --git a/p2d/p2d.py b/p2d/p2d.py index f41104e..1e6f560 100644 --- a/p2d/p2d.py +++ b/p2d/p2d.py @@ -70,6 +70,7 @@ def p2d(args): continue problem['domjudge_server_version'] = -1 problem.pop('domjudge_id', None) + problem.pop('domjudge_externalid', None) p2d_utils.save_config_yaml(config, contest_dir) logging.info('Deleted the DOMjudge IDs from config.yaml.') diff --git a/p2d/p2d_utils.py b/p2d/p2d_utils.py index a777c07..6ac720f 100644 --- a/p2d/p2d_utils.py +++ b/p2d/p2d_utils.py @@ -191,7 +191,7 @@ def manage_domjudge(config, domjudge_dir, problem): assert('domjudge_id' in problem) zip_file = os.path.join(domjudge_dir, problem['name'] + '.zip') zip_file_copy = os.path.join(domjudge_dir, - problem['domjudge_id'] + '.zip') + problem['domjudge_externalid'] + '.zip') shutil.copyfile(zip_file, zip_file_copy) if not domjudge_api.update_problem_api( @@ -202,7 +202,7 @@ def manage_domjudge(config, domjudge_dir, problem): problem['domjudge_server_version'] = local_version - logging.info('Updated the DOMjudge package on the server \'%s\', with externalid = \'%s\'.' % (config['domjudge']['server'], problem['domjudge_id'])) + logging.info('Updated the DOMjudge package on the server \'%s\', with id = \'%s\'.' % (config['domjudge']['server'], problem['domjudge_id'])) # Generates contest_dir/tex/problemset.pdf and contest_dir/tex/solutions.pdf. def generate_problemset_solutions(config, contest_dir): @@ -283,7 +283,7 @@ def validate_config_yaml(config): set(config['domjudge'].keys()) != set(domjudge_keys): logging.warning('The subdictionary \'domjudge\' of \'config.yaml\' must contain they keys: %s.' % ', '.join(domjudge_keys)) - problem_keys = ['name', 'label', 'color', 'author', 'preparation', 'override_time_limit', 'override_memory_limit', 'polygon_id', 'polygon_version', 'domjudge_local_version', 'domjudge_server_version'] + problem_keys = ['name', 'label', 'color', 'author', 'preparation', 'override_time_limit', 'override_memory_limit', 'polygon_id', 'polygon_version', 'domjudge_local_version', 'domjudge_server_version', 'domjudge_id', 'domjudge_externalid'] for problem in config['problems']: if 'name' not in problem: