From 14b2024f42f4c8ae6166d07e64179769797723c9 Mon Sep 17 00:00:00 2001 From: mzuenni Date: Sat, 17 Feb 2024 15:50:11 +0100 Subject: [PATCH] add uuid support --- bin/config.py | 5 +++++ bin/problem.py | 11 +++++++++++ bin/skel.py | 1 + bin/util.py | 15 +++++++++++++++ skel/problem/problem.yaml | 1 + test/problems/boolfind/problem.yaml | 1 + test/problems/different/problem.yaml | 3 +++ test/problems/fltcmp/problem.yaml | 1 + test/problems/generatorincludes/problem.yaml | 1 + test/problems/guess/problem.yaml | 1 + test/problems/guessnoeofcheck/problem.yaml | 2 +- test/problems/hello/problem.yaml | 1 + test/problems/helloproblemtools/problem.yaml | 1 + test/problems/hellounix/problem.yaml | 1 + test/problems/hellowholeworld/problem.yaml | 1 + test/problems/identity/problem.yaml | 1 + test/problems/test_problem_config/problem.yaml | 1 + 17 files changed, 47 insertions(+), 1 deletion(-) diff --git a/bin/config.py b/bin/config.py index 96221da6..c37d40a3 100644 --- a/bin/config.py +++ b/bin/config.py @@ -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 diff --git a/bin/problem.py b/bin/problem.py index bc6063ba..b7754bf2 100644 --- a/bin/problem.py +++ b/bin/problem.py @@ -106,6 +106,7 @@ def _read_settings(self): 'validation': 'default', 'validator_flags': [], 'author': '', + 'uuid': None, } # parse problem.yaml @@ -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): diff --git a/bin/skel.py b/bin/skel.py index ad85afd0..634584ca 100644 --- a/bin/skel.py +++ b/bin/skel.py @@ -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) diff --git a/bin/util.py b/bin/util.py index 2b08c0a3..5037593a 100644 --- a/bin/util.py +++ b/bin/util.py @@ -14,6 +14,7 @@ import tempfile import yaml as yamllib import errno +import secrets from enum import Enum from pathlib import Path @@ -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 diff --git a/skel/problem/problem.yaml b/skel/problem/problem.yaml index 1902f5ef..c4abb2fa 100644 --- a/skel/problem/problem.yaml +++ b/skel/problem/problem.yaml @@ -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' diff --git a/test/problems/boolfind/problem.yaml b/test/problems/boolfind/problem.yaml index 77967c1a..448e1735 100644 --- a/test/problems/boolfind/problem.yaml +++ b/test/problems/boolfind/problem.yaml @@ -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' diff --git a/test/problems/different/problem.yaml b/test/problems/different/problem.yaml index fbc1f7fb..48ed7e26 100644 --- a/test/problems/different/problem.yaml +++ b/test/problems/different/problem.yaml @@ -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: diff --git a/test/problems/fltcmp/problem.yaml b/test/problems/fltcmp/problem.yaml index a556474d..8aa3745d 100644 --- a/test/problems/fltcmp/problem.yaml +++ b/test/problems/fltcmp/problem.yaml @@ -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' diff --git a/test/problems/generatorincludes/problem.yaml b/test/problems/generatorincludes/problem.yaml index b879e288..4b25b637 100644 --- a/test/problems/generatorincludes/problem.yaml +++ b/test/problems/generatorincludes/problem.yaml @@ -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' diff --git a/test/problems/guess/problem.yaml b/test/problems/guess/problem.yaml index 4150da78..c0a47e7e 100644 --- a/test/problems/guess/problem.yaml +++ b/test/problems/guess/problem.yaml @@ -1,6 +1,7 @@ name: en: Guess the Number source: Kattis +uuid: 4c1ca09b-af36-4cb6-82ec-2cd029c02a6a license: cc by-sa validation: custom interactive diff --git a/test/problems/guessnoeofcheck/problem.yaml b/test/problems/guessnoeofcheck/problem.yaml index fcb51934..cf3967e9 100644 --- a/test/problems/guessnoeofcheck/problem.yaml +++ b/test/problems/guessnoeofcheck/problem.yaml @@ -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 diff --git a/test/problems/hello/problem.yaml b/test/problems/hello/problem.yaml index c44c44de..5b3d2aaf 100644 --- a/test/problems/hello/problem.yaml +++ b/test/problems/hello/problem.yaml @@ -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' diff --git a/test/problems/helloproblemtools/problem.yaml b/test/problems/helloproblemtools/problem.yaml index 366f7942..f3792eab 100644 --- a/test/problems/helloproblemtools/problem.yaml +++ b/test/problems/helloproblemtools/problem.yaml @@ -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 diff --git a/test/problems/hellounix/problem.yaml b/test/problems/hellounix/problem.yaml index 17ae7905..620c0faf 100644 --- a/test/problems/hellounix/problem.yaml +++ b/test/problems/hellounix/problem.yaml @@ -4,6 +4,7 @@ author: various # unix-y operating systems source: source_url: +uuid: 20798d22-3227-4e48-9877-7f73d3d3236e license: rights_owner: validation: default diff --git a/test/problems/hellowholeworld/problem.yaml b/test/problems/hellowholeworld/problem.yaml index fac7f07f..00c2c30b 100644 --- a/test/problems/hellowholeworld/problem.yaml +++ b/test/problems/hellowholeworld/problem.yaml @@ -3,4 +3,5 @@ name: de: Hallo, ganze Welt! da: Hej, hele verden! author: Thore Husfeldt +uuid: c7c28c31-809a-400c-84ae-f6a3b29a217a validation: default diff --git a/test/problems/identity/problem.yaml b/test/problems/identity/problem.yaml index ead3d96b..e37ef209 100644 --- a/test/problems/identity/problem.yaml +++ b/test/problems/identity/problem.yaml @@ -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' diff --git a/test/problems/test_problem_config/problem.yaml b/test/problems/test_problem_config/problem.yaml index 72609246..537c2d80 100644 --- a/test/problems/test_problem_config/problem.yaml +++ b/test/problems/test_problem_config/problem.yaml @@ -1,2 +1,3 @@ name: 'ABC XYZ' validation: 'custom' +uuid: 58c89b2d-616c-4291-ab8a-710b4e6cb978