Skip to content

Commit

Permalink
add uuid support
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni committed Feb 17, 2024
1 parent 15b0a81 commit 14b2024
Show file tree
Hide file tree
Showing 17 changed files with 47 additions and 1 deletion.
5 changes: 5 additions & 0 deletions bin/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,3 +126,8 @@ def set_default_args():

def get_timeout():
return args.timeout or DEFAULT_TIMEOUT


# Randomly generated uuid4 for BAPCtools
BAPC_UUID = '8ee7605a-d1ce-47b3-be37-15de5acd757e'
BAPC_UUID_PREFIX = 8
11 changes: 11 additions & 0 deletions bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ def _read_settings(self):
'validation': 'default',
'validator_flags': [],
'author': '',
'uuid': None,
}

# parse problem.yaml
Expand Down Expand Up @@ -160,6 +161,16 @@ def _read_settings(self):

self.interactive = self.settings.validation == 'custom interactive'

if self.settings.uuid == None:
# try to always display the same uuid (until restart)
stored_uuid = self.tmpdir / '.uuid'
if stored_uuid.is_file():
self.settings.uuid = stored_uuid.read_text().strip()
else:
self.settings.uuid = generate_problem_uuid()
stored_uuid.write_text(self.settings.uuid)
warn(f'Missing UUID for {self.name}, add "uuid: {self.settings.uuid}" to problem.yaml')

# Walk up from absolute `path` (a file or directory) looking for the first testdata.yaml
# file, and return its contents, or None if no testdata.yaml is found.
def get_testdata_yaml(p, path):
Expand Down
1 change: 1 addition & 0 deletions bin/skel.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@ def new_problem():
variables['rights_owner'] = _ask_variable_string(
'rights owner', variables.get('rights_owner', 'author')
)
variables['uuid'] = generate_problem_uuid()

# Copy tree from the skel directory, next to the contest, if it is found.
skeldir, preserve_symlinks = get_skel_dir(target_dir)
Expand Down
15 changes: 15 additions & 0 deletions bin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import tempfile
import yaml as yamllib
import errno
import secrets

from enum import Enum
from pathlib import Path
Expand Down Expand Up @@ -1049,3 +1050,17 @@ def hash_file_or_dir(file_or_dir, buffer_size=65536):
)
else:
return hash_file(file_or_dir)


def generate_problem_uuid():
uuid = bytearray(secrets.token_bytes(16))
# mark this as v8 uuid (custom uuid) variant 0
uuid[6] &= 0b0000_1111
uuid[6] |= 0b1000_0000
uuid[8] &= 0b0011_1111
# format as uuid
uuid = uuid.hex()
uuid = f'{uuid[0:8]}-{uuid[8:12]}-{uuid[12:16]}-{uuid[16:20]}-{uuid[20:32]}'
# make the first bytes BAPCtools specific
uuid = config.BAPC_UUID[:config.BAPC_UUID_PREFIX] + uuid[config.BAPC_UUID_PREFIX:]
return uuid
1 change: 1 addition & 0 deletions skel/problem/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ author: {%author%}
source: {%source%}
# contest.region.eu
source_url: {%source_url%}
uuid: {%uuid%}
license: {%license%}
rights_owner: {%rights_owner%}
# 'default', 'custom', or 'custom interactive'
Expand Down
1 change: 1 addition & 0 deletions test/problems/boolfind/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: DOMjudge
source:
# 2020.bapc.eu
source_url:
uuid: 8f7ed1ba-43f5-424e-9af4-8a5f2e428ce3
license:
rights_owner:
# 'default', 'custom', or 'interactive'
Expand Down
3 changes: 3 additions & 0 deletions test/problems/different/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ name:
source: Kattis
# source_url:

# Unique problem uuid
uuid: FFFFFFFF-FFFF-FFFF-FFFF-FFFFFFFFFFFF

## Who owns the rights to the problem (default: value of author, or
## value of source if no author given).
# rights_owner:
Expand Down
1 change: 1 addition & 0 deletions test/problems/fltcmp/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: DOMjudge
source:
# 2020.bapc.eu
source_url:
uuid: 407efad0-da0d-49a4-b925-329e929bc990
license:
rights_owner:
# 'default', 'custom', or 'interactive'
Expand Down
1 change: 1 addition & 0 deletions test/problems/generatorincludes/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: Thore Husfeldt
source: Problems
# contest.region.eu
source_url:
uuid: 745cc994-4c3d-40cf-97c2-cc2a72af1884
license: cc by-sa
rights_owner: author
# 'default', 'custom', or 'custom interactive'
Expand Down
1 change: 1 addition & 0 deletions test/problems/guess/problem.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name:
en: Guess the Number
source: Kattis
uuid: 4c1ca09b-af36-4cb6-82ec-2cd029c02a6a
license: cc by-sa

validation: custom interactive
Expand Down
2 changes: 1 addition & 1 deletion test/problems/guessnoeofcheck/problem.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
source: Kattis
uuid: 1bf54011-8f0f-44fb-8030-15d9c1583979
license: cc by-sa

validation: custom interactive

# Override standard limits: say that the TLE solutions provided should
Expand Down
1 change: 1 addition & 0 deletions test/problems/hello/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: DOMjudge
source:
# 2020.bapc.eu
source_url:
uuid: 323a5d9c-b38a-4110-8483-2846c920c1ee
license:
rights_owner:
# 'default', 'custom', or 'interactive'
Expand Down
1 change: 1 addition & 0 deletions test/problems/helloproblemtools/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name:
sv: Hej Världen!

source: Kattis
uuid: 2116c8d6-814f-427c-af45-a51bc735840c
license: public domain

# Fix memory limit at 512 MB. (Note that for most problems, this
Expand Down
1 change: 1 addition & 0 deletions test/problems/hellounix/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ author: various
# unix-y operating systems
source:
source_url:
uuid: 20798d22-3227-4e48-9877-7f73d3d3236e
license:
rights_owner:
validation: default
Expand Down
1 change: 1 addition & 0 deletions test/problems/hellowholeworld/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ name:
de: Hallo, ganze Welt!
da: Hej, hele verden!
author: Thore Husfeldt
uuid: c7c28c31-809a-400c-84ae-f6a3b29a217a
validation: default
1 change: 1 addition & 0 deletions test/problems/identity/problem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: Identity
author: Ragnar Groot Koerkamp
source:
source_url:
uuid: a7d29d67-9b0b-4fd4-ae56-ab2cad5919ab
license:
rights_owner:
# 'default', 'custom', or 'interactive'
Expand Down
1 change: 1 addition & 0 deletions test/problems/test_problem_config/problem.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
name: 'ABC XYZ'
validation: 'custom'
uuid: 58c89b2d-616c-4291-ab8a-710b4e6cb978

0 comments on commit 14b2024

Please sign in to comment.