Skip to content

Commit

Permalink
Fixed domjudge id vs externalid
Browse files Browse the repository at this point in the history
  • Loading branch information
dario2994 committed Dec 3, 2022
1 parent 8a352d4 commit 0e8c245
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 6 additions & 5 deletions p2d/domjudge_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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']
Expand All @@ -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
1 change: 1 addition & 0 deletions p2d/p2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down
6 changes: 3 additions & 3 deletions p2d/p2d_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 0e8c245

Please sign in to comment.