From 10a5efb293af2c786f2f59daaca5577ed161280a Mon Sep 17 00:00:00 2001 From: Boming Zhang Date: Wed, 25 Jun 2025 22:05:59 -0400 Subject: [PATCH] feat: set log path based on suffix --- joj3_config_generator/generator.py | 8 ++++++-- joj3_config_generator/models/const.py | 3 ++- joj3_config_generator/models/task.py | 11 +++++++++-- tests/convert/basic/task.json | 2 +- tests/convert/clang-tidy/task.json | 2 +- tests/convert/cppcheck/task.json | 2 +- tests/convert/cpplint/task.json | 2 +- tests/convert/diff/task.json | 2 +- tests/convert/elf/task.json | 2 +- tests/convert/keyword/task.json | 2 +- tests/convert/result-detail/task.json | 2 +- tests/convert/unnecessary/task.json | 2 +- 12 files changed, 26 insertions(+), 14 deletions(-) diff --git a/joj3_config_generator/generator.py b/joj3_config_generator/generator.py index f009eaf..f41843d 100644 --- a/joj3_config_generator/generator.py +++ b/joj3_config_generator/generator.py @@ -2,7 +2,11 @@ import os from typing import Dict from joj3_config_generator.models import answer, joj1, repo, result, task -from joj3_config_generator.models.const import ACTOR_CSV_PATH, JOJ3_LOG_PATH +from joj3_config_generator.models.const import ( + ACTOR_CSV_PATH, + JOJ3_LOG_BASE_PATH, + JOJ3_LOG_FILENAME, +) from joj3_config_generator.transformers.answer import get_task_conf_from_answers from joj3_config_generator.transformers.joj1 import get_task_conf_from_joj1 from joj3_config_generator.transformers.repo import ( @@ -25,7 +29,7 @@ def convert_joj3_conf(repo_conf: repo.Config, task_conf: task.Config) -> result. result_conf = result.Config( name=task_conf.task.name, # exact folder difference specified by type - log_path=str(JOJ3_LOG_PATH), + log_path=str(JOJ3_LOG_BASE_PATH / task_conf.suffix / JOJ3_LOG_FILENAME), # TODO: remove these 2 fields, will be handled in the health check stage expire_unix_timestamp=int(task_conf.release.end_time.timestamp()), effective_unix_timestamp=int(task_conf.release.begin_time.timestamp()), diff --git a/joj3_config_generator/models/const.py b/joj3_config_generator/models/const.py index 981ef7c..ad7d4d5 100644 --- a/joj3_config_generator/models/const.py +++ b/joj3_config_generator/models/const.py @@ -13,6 +13,7 @@ DEFAULT_PATH_ENV = "PATH=/usr/bin:/bin:/usr/local/bin" JOJ3_CONFIG_ROOT = PurePosixPath("/home/tt/.config/joj") TEAPOT_CONFIG_ROOT = PurePosixPath("/home/tt/.config/teapot") CACHE_ROOT = PurePosixPath("/home/tt/.cache") -JOJ3_LOG_PATH = CACHE_ROOT / "joj3" / "joj3.log" +JOJ3_LOG_BASE_PATH = CACHE_ROOT / "joj3" +JOJ3_LOG_FILENAME = "joj3.log" TEAPOT_LOG_PATH = CACHE_ROOT / "joint-teapot-debug.log" ACTOR_CSV_PATH = JOJ3_CONFIG_ROOT / "students.csv" diff --git a/joj3_config_generator/models/task.py b/joj3_config_generator/models/task.py index 6c198dd..52966a8 100644 --- a/joj3_config_generator/models/task.py +++ b/joj3_config_generator/models/task.py @@ -270,9 +270,16 @@ class Config(BaseModel): ) scoreboard: str = "scoreboard.csv" + suffix: str = Field("", exclude=True) + + @model_validator(mode="after") + def set_suffix(self) -> "Config": + if not self.suffix: + self.suffix = re.split(r"[-_/\s]+", self.task.name)[0] + return self + @model_validator(mode="after") def set_scoreboard(self) -> "Config": if self.scoreboard == "auto": - suffix = re.split(r"[-_/\s]+", self.task.name)[0] - self.scoreboard = f"scoreboard-{suffix}.csv" + self.scoreboard = f"scoreboard-{self.suffix}.csv" return self diff --git a/tests/convert/basic/task.json b/tests/convert/basic/task.json index d91eb05..a4097a5 100644 --- a/tests/convert/basic/task.json +++ b/tests/convert/basic/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/clang-tidy/task.json b/tests/convert/clang-tidy/task.json index c9ae0ca..4450085 100644 --- a/tests/convert/clang-tidy/task.json +++ b/tests/convert/clang-tidy/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/cppcheck/task.json b/tests/convert/cppcheck/task.json index 07abd05..a7b2893 100644 --- a/tests/convert/cppcheck/task.json +++ b/tests/convert/cppcheck/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/cpplint/task.json b/tests/convert/cpplint/task.json index c69bcdc..df13ac6 100644 --- a/tests/convert/cpplint/task.json +++ b/tests/convert/cpplint/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/diff/task.json b/tests/convert/diff/task.json index 11d3e19..07345ce 100644 --- a/tests/convert/diff/task.json +++ b/tests/convert/diff/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/elf/task.json b/tests/convert/elf/task.json index abcd359..986ffb2 100644 --- a/tests/convert/elf/task.json +++ b/tests/convert/elf/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/keyword/task.json b/tests/convert/keyword/task.json index 7db7905..ccd3678 100644 --- a/tests/convert/keyword/task.json +++ b/tests/convert/keyword/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/result-detail/task.json b/tests/convert/result-detail/task.json index 7c50165..2f222a0 100644 --- a/tests/convert/result-detail/task.json +++ b/tests/convert/result-detail/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv", diff --git a/tests/convert/unnecessary/task.json b/tests/convert/unnecessary/task.json index a478749..79dd4be 100644 --- a/tests/convert/unnecessary/task.json +++ b/tests/convert/unnecessary/task.json @@ -1,6 +1,6 @@ { "name": "hw7 ex2", - "logPath": "/home/tt/.cache/joj3/joj3.log", + "logPath": "/home/tt/.cache/joj3/hw7/joj3.log", "expireUnixTimestamp": 0, "effectiveUnixTimestamp": 0, "actorCsvPath": "/home/tt/.config/joj/students.csv",