feat: joj3 commands load settings from file
This commit is contained in:
parent
5426d4c0b2
commit
0c2fdaaa34
|
@ -6,6 +6,7 @@ from typing import List
|
|||
from git import Repo
|
||||
from typer import Argument, Option, Typer, echo
|
||||
|
||||
from joint_teapot.config import Settings, set_settings, settings
|
||||
from joint_teapot.teapot import Teapot
|
||||
from joint_teapot.utils import joj3
|
||||
from joint_teapot.utils.logger import logger
|
||||
|
@ -205,10 +206,11 @@ def unsubscribe_from_repos(pattern: str = Argument("")) -> None:
|
|||
|
||||
|
||||
@app.command(
|
||||
"JOJ3-scoreboard",
|
||||
"joj3-scoreboard",
|
||||
help="parse JOJ3 score json file into scoreboard and upload to gitea",
|
||||
)
|
||||
def JOJ3_scoreboard(
|
||||
env_path: str = Argument("", help="path to .env file"),
|
||||
scorefile_path: str = Argument(
|
||||
"", help="path to score json file generated by JOJ3"
|
||||
),
|
||||
|
@ -224,6 +226,7 @@ def JOJ3_scoreboard(
|
|||
"", help="name of scoreboard file in the gitea repo"
|
||||
),
|
||||
) -> None:
|
||||
set_settings(Settings(_env_file=env_path))
|
||||
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
|
||||
repo: Repo = tea.pot.git.get_repo(repo_name)
|
||||
if "grading" not in repo.remote().refs:
|
||||
|
@ -248,10 +251,11 @@ def JOJ3_scoreboard(
|
|||
|
||||
|
||||
@app.command(
|
||||
"JOJ3-failed-table",
|
||||
"joj3-failed-table",
|
||||
help="parse JOJ3 score json file into failed table markdown file and upload to gitea",
|
||||
)
|
||||
def JOJ3_failed_table(
|
||||
env_path: str = Argument("", help="path to .env file"),
|
||||
scorefile_path: str = Argument(
|
||||
"", help="path to score json file generated by JOJ3"
|
||||
),
|
||||
|
@ -271,6 +275,7 @@ def JOJ3_failed_table(
|
|||
"", help="name of failed table file in the gitea repo"
|
||||
),
|
||||
) -> None:
|
||||
set_settings(Settings(_env_file=env_path))
|
||||
repo_path = tea.pot.git.repo_clean_and_checkout(repo_name, "grading")
|
||||
repo: Repo = tea.pot.git.get_repo(repo_name)
|
||||
if "grading" not in repo.remote().refs:
|
||||
|
|
|
@ -48,4 +48,9 @@ def get_settings() -> Settings:
|
|||
return Settings()
|
||||
|
||||
|
||||
def set_settings(new_settings: Settings) -> None:
|
||||
for field, value in new_settings.model_dump(exclude_unset=True).items():
|
||||
setattr(settings, field, value)
|
||||
|
||||
|
||||
settings: Settings = get_settings()
|
||||
|
|
|
@ -57,10 +57,10 @@ def generate_scoreboard(
|
|||
|
||||
# Update data
|
||||
with open(score_file_path) as json_file:
|
||||
scorefile: List[Dict[str, Any]] = json.load(json_file)
|
||||
stages: List[Dict[str, Any]] = json.load(json_file)
|
||||
|
||||
exercise_total_score = 0
|
||||
for stage in scorefile:
|
||||
for stage in stages:
|
||||
for result in stage["results"]:
|
||||
exercise_total_score += result["score"]
|
||||
submitter_row[columns.index(exercise_name)] = str(exercise_total_score)
|
||||
|
|
Loading…
Reference in New Issue
Block a user