Introduce Submission
This commit is contained in:
parent
3bb2282dd0
commit
d992e18bbd
7 changed files with 122 additions and 46 deletions
|
@ -2,37 +2,33 @@
|
|||
|
||||
|
||||
import os
|
||||
from typing import List
|
||||
|
||||
|
||||
from constants import HOMEWORK
|
||||
from git import checkout_branch
|
||||
from utils import make_pair, get_branch, mkcd
|
||||
from utils import mkcd
|
||||
from submission import Submission
|
||||
|
||||
|
||||
class BaseCommand:
|
||||
def __init__(self, submissions):
|
||||
self.submissions = map(make_pair, submissions)
|
||||
self.branch = None
|
||||
def __init__(self, submissions: List[Submission]) -> None:
|
||||
self.submissions = submissions
|
||||
|
||||
def __call__(self):
|
||||
for login, submission in self.submissions:
|
||||
self.branch = get_branch(login)
|
||||
def __call__(self) -> None:
|
||||
for submission in self.submissions:
|
||||
self.exec(submission)
|
||||
|
||||
self.exec(login, submission)
|
||||
|
||||
def exec(self, login: str, submission: str):
|
||||
def exec(self, submission: Submission) -> None:
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
class BaseGitCommand(BaseCommand):
|
||||
def __call__(self):
|
||||
for login, submission in self.submissions:
|
||||
self.branch = get_branch(login)
|
||||
def __call__(self) -> None:
|
||||
for submission in self.submissions:
|
||||
checkout_branch(submission.branch)
|
||||
mkcd(f"{submission.homework}/{submission.login}")
|
||||
|
||||
checkout_branch(self.branch)
|
||||
mkcd(f"{HOMEWORK}/{login}")
|
||||
|
||||
self.exec(login, submission)
|
||||
self.exec(submission)
|
||||
|
||||
os.chdir("../..")
|
||||
checkout_branch("master")
|
||||
checkout_branch("master")
|
||||
|
|
|
@ -6,6 +6,7 @@ import json
|
|||
|
||||
from commands.base import BaseCommand
|
||||
from gitlab import get_mrs_for_branch, get_comments
|
||||
from submission import Submission
|
||||
|
||||
|
||||
class Comments(BaseCommand):
|
||||
|
@ -48,14 +49,14 @@ class Comments(BaseCommand):
|
|||
print()
|
||||
print()
|
||||
|
||||
def exec(self, login: str, submission: str):
|
||||
mrs = get_mrs_for_branch(self.branch)
|
||||
def exec(self, submission: Submission) -> None:
|
||||
mrs = get_mrs_for_branch(submission.branch)
|
||||
if not mrs:
|
||||
return
|
||||
|
||||
iid = mrs[0]["iid"]
|
||||
comments = get_comments(iid)
|
||||
|
||||
print(f"# {self.branch}")
|
||||
print(f"### {submission.branch.center(20)} ###")
|
||||
self.print_comments(comments)
|
||||
print(f"# {self.branch}")
|
||||
print(f"### {submission.branch.center(20)} ###")
|
||||
|
|
|
@ -3,10 +3,11 @@
|
|||
|
||||
from commands.base import BaseCommand
|
||||
from gitlab import get_mrs_for_branch, merge_mr
|
||||
from submission import Submission
|
||||
|
||||
|
||||
class Merge(BaseCommand):
|
||||
def exec(self, login: str, submission: str):
|
||||
iid = get_mrs_for_branch(self.branch)[0]["iid"]
|
||||
def exec(self, submission: Submission) -> None:
|
||||
iid = get_mrs_for_branch(submission.branch)[0]["iid"]
|
||||
|
||||
merge_mr(iid)
|
||||
merge_mr(iid)
|
||||
|
|
|
@ -4,25 +4,24 @@
|
|||
import re
|
||||
|
||||
|
||||
from constants import HOMEWORK, SUFFIX
|
||||
from commands.base import BaseGitCommand
|
||||
from git import add_files, commit, push
|
||||
from gitlab import post_mr
|
||||
from submission import Submission
|
||||
from utils import run_cmd
|
||||
|
||||
|
||||
class MergeRequests(BaseGitCommand):
|
||||
@staticmethod
|
||||
def get_files(submission: str) -> None:
|
||||
relative_path = f"/home/kontr/kontr/_tmp_/ib111/{HOMEWORK}/{submission}"
|
||||
files = f"{{master-naostro/LoadTest/{HOMEWORK}.py,teacher_email}}"
|
||||
def get_files(submission: Submission) -> None:
|
||||
files = f"{{master-naostro/LoadTest/{submission.homework}.py,teacher_email}}"
|
||||
|
||||
if run_cmd("rsync", "-avzP", f"aisa:{relative_path}/{files}", "./")[0] != 0:
|
||||
if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0:
|
||||
exit(1)
|
||||
|
||||
@staticmethod
|
||||
def call_flake() -> None:
|
||||
process = run_cmd("flake8", "--exit-zero", f"{HOMEWORK}.py")[1]
|
||||
def call_flake(submission: Submission) -> None:
|
||||
process = run_cmd("flake8", "--exit-zero", f"{submission.homework}.py")[1]
|
||||
with open("flake.log", "w") as f:
|
||||
print(process.stdout, file=f)
|
||||
|
||||
|
@ -34,20 +33,20 @@ class MergeRequests(BaseGitCommand):
|
|||
|
||||
return match.group(1) if match else contents
|
||||
|
||||
def exec(self, login: str, submission: str) -> None:
|
||||
def exec(self, submission: Submission) -> None:
|
||||
self.get_files(submission)
|
||||
self.call_flake()
|
||||
self.call_flake(submission)
|
||||
|
||||
add_files(f"{HOMEWORK}.py", "flake.log")
|
||||
commit(f'"Add sources and flake log ({HOMEWORK}{SUFFIX} {login})"')
|
||||
push("origin", self.branch)
|
||||
add_files(f"{submission.homework}.py", "flake.log")
|
||||
commit(f'"Add sources and flake log ({submission.branch} {submission.login})"')
|
||||
push("origin", submission.branch)
|
||||
|
||||
post_mr(
|
||||
source_branch=self.branch,
|
||||
source_branch=submission.branch,
|
||||
target_branch="master",
|
||||
title=f"[{HOMEWORK}{SUFFIX}] {login}",
|
||||
title=f"[{submission.branch}] {submission.login}",
|
||||
description=f"```\n{self.get_mail()}\n```",
|
||||
labels=HOMEWORK,
|
||||
labels=submission.homework,
|
||||
remove_source_branch="true",
|
||||
assignee_ids=["1772"],
|
||||
)
|
||||
|
|
|
@ -2,8 +2,9 @@
|
|||
|
||||
|
||||
from commands.base import BaseCommand
|
||||
from submission import print_submissions, Submission
|
||||
|
||||
|
||||
class Test(BaseCommand):
|
||||
def exec(self, login: str, submission: str):
|
||||
print(f"{login} - {submission}")
|
||||
def exec(self, submission: Submission) -> None:
|
||||
print(f"{submission.login}, {submission.submitted_at}, {submission.points}")
|
||||
|
|
|
@ -3,11 +3,12 @@
|
|||
|
||||
from commands.base import BaseCommand
|
||||
from gitlab import get_mrs_for_branch, set_assignees
|
||||
from submission import Submission
|
||||
|
||||
|
||||
class UpdateAssignees(BaseCommand):
|
||||
def exec(self, login: str, submission: str) -> None:
|
||||
iid = get_mrs_for_branch(self.branch)[0]["iid"]
|
||||
def exec(self, submission: Submission) -> None:
|
||||
iid = get_mrs_for_branch(submission.branch)[0]["iid"]
|
||||
|
||||
print(f"{login} @ {self.branch} : {iid}")
|
||||
print(f"{submission.login} @ {submission.branch} : {iid}")
|
||||
set_assignees(iid, [39, 1772])
|
||||
|
|
77
submission.py
Normal file
77
submission.py
Normal file
|
@ -0,0 +1,77 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import datetime
|
||||
from typing import Dict, List
|
||||
|
||||
|
||||
class Submission:
|
||||
def __init__(
|
||||
self,
|
||||
uco: str,
|
||||
login: str,
|
||||
path: str,
|
||||
points: float,
|
||||
homework: str,
|
||||
correction: bool,
|
||||
) -> None:
|
||||
self.uco = uco
|
||||
self.login = login
|
||||
self.path = path
|
||||
self.points = points
|
||||
self.homework = homework
|
||||
self.correction = correction
|
||||
|
||||
self.submitted_at = None
|
||||
self.submitted_before_deadline = None
|
||||
self.flag = None
|
||||
self.branch = f"{homework}{'-opravne' if correction else ''}-{login}"
|
||||
self.__set_submission_date()
|
||||
|
||||
def __set_submission_date(self) -> None:
|
||||
self.submitted_at = datetime.datetime.strptime(
|
||||
self.path.split("/")[-1][-16:], "%Y_%m%d_%H%M%S"
|
||||
)
|
||||
|
||||
def set_late_tag(self, deadline: datetime.datetime) -> None:
|
||||
self.submitted_before_deadline = self.submitted_at < deadline
|
||||
if not self.submitted_before_deadline:
|
||||
self.flag = "LATE"
|
||||
|
||||
|
||||
def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None:
|
||||
header = (
|
||||
"| "
|
||||
+ " | ".join(
|
||||
[
|
||||
"###",
|
||||
"UCO".center(6),
|
||||
"LOGIN".center(8),
|
||||
"SUBMITTED".center(19),
|
||||
"POINTS",
|
||||
"FLAG".center(6),
|
||||
]
|
||||
)
|
||||
+ " |"
|
||||
)
|
||||
SEPARATOR = "-" * len(header)
|
||||
print(SEPARATOR)
|
||||
print(header)
|
||||
print(SEPARATOR)
|
||||
|
||||
FORMAT = "| {:>3} | {:>6s} | {:>8s} | {} | {:>6.2f} | {:^6s} |"
|
||||
|
||||
for _, submissions in all_submissions.items():
|
||||
for i, submission in enumerate(submissions):
|
||||
date = submission.submitted_at.strftime("%Y-%m-%d %H:%M:%S")
|
||||
print(
|
||||
FORMAT.format(
|
||||
i,
|
||||
submission.uco if i == 0 else "",
|
||||
submission.login if i == 0 else "",
|
||||
date,
|
||||
submission.points,
|
||||
submission.flag if submission.flag else "",
|
||||
)
|
||||
)
|
||||
print(SEPARATOR)
|
Reference in a new issue