Skip to content

Commit

Permalink
Unify homework IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
George V. Kouryachy (Fr. Br. George) committed Oct 8, 2023
1 parent f4806e1 commit 39f7805
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion hworker/deliver/file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def download_all():
if len(contents) > 0:
depot.store(
Homework(
ID=f"{_depot_prefix}{TASK_ID}",
ID=f"{_depot_prefix}.{userdir.name}:{deliver_id}",
USER_ID=USER_ID,
TASK_ID=TASK_ID,
timestamp=max(c.timestamp for c in contents.values()),
Expand Down
22 changes: 18 additions & 4 deletions hworker/deliver/git/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
"""Downloads solutions from repos"""
import datetime
import os
import re
from pathlib import Path
from tempfile import gettempdir

import git

from ... import depot
from ...config import get_git_directory, get_repos, get_git_uids, repo_to_uid, get_tasks_list, get_task_info
from ...config import (
get_git_directory,
get_repos,
get_git_uids,
repo_to_uid,
get_tasks_list,
get_task_info,
uid_to_repo,
)
from ...depot import store
from ...depot.objects import Homework, FileObject
from ...log import get_logger

_depot_prefix = "g"
reUDID = re.compile(r".*://([^/]+).*/([^/]+)/([^/]+)")


def local_path(student_id: str) -> str:
"""Convert student id to local repo path
Expand Down Expand Up @@ -108,17 +120,19 @@ def download_all() -> None:
repo = git.Repo(local_path(student_id))
for task in get_tasks_list():
repo.git.checkout(repo.heads[0])
if os.path.isdir((task_path := Path(local_path(student_id), get_task_info(task).get("deliver_ID", "")))):
task_d_ID = get_task_info(task).get("deliver_ID", "")
repo_d_ID = reUDID.sub(r"\2@\1:\3", uid_to_repo(student_id))
if (task_path := Path(local_path(student_id), task_d_ID)).is_dir():
commits = [_ for _ in get_commits(repo, task_path) if _]
for commit in commits:
repo.git.checkout(commit[0])
content = get_homework_content(repo, task_path)
store(
Homework(
content=content,
ID=f"{student_id}:{task}",
ID=f"{_depot_prefix}.{repo_d_ID}:{task_d_ID}",
USER_ID=student_id,
TASK_ID=os.path.join(task),
TASK_ID=task,
timestamp=float(commit[1]),
is_broken=False,
)
Expand Down
2 changes: 1 addition & 1 deletion hworker/deliver/imap/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def download_all():
else:
depot.store(
Homework(
ID=f"{_depot_prefix}{mail.uid}",
ID=f"{_depot_prefix}.{mail.uid}",
USER_ID=USER_ID,
TASK_ID=TASK_ID,
timestamp=max(map(attrgetter("timestamp"), contents.values()), default=_default_timestamp),
Expand Down

0 comments on commit 39f7805

Please sign in to comment.