Mail from mailbox

Closes #6
This commit is contained in:
Matej Focko 2019-11-30 22:47:08 +01:00
parent 4437e1a058
commit a79b3f4319
3 changed files with 18 additions and 11 deletions

View file

@ -14,7 +14,7 @@ from utils import run_cmd
class MergeRequests(BaseGitCommand): class MergeRequests(BaseGitCommand):
@staticmethod @staticmethod
def get_files(submission: Submission) -> None: def get_files(submission: Submission) -> None:
files = f"{{master-naostro/LoadTest/{submission.homework}.py,teacher_email}}" files = f"master-naostro/LoadTest/{submission.homework}.py"
if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0: if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0:
exit(1) exit(1)
@ -25,14 +25,6 @@ class MergeRequests(BaseGitCommand):
with open("flake.log", "w") as f: with open("flake.log", "w") as f:
print(process.stdout, file=f) print(process.stdout, file=f)
@staticmethod
def get_mail() -> None:
with open("teacher_email") as file:
contents = file.read()
match = re.search(r"<pre>((.*\s+)+)<\/pre>", contents)
return match.group(1) if match else contents
def exec(self, submission: Submission) -> None: def exec(self, submission: Submission) -> None:
self.get_files(submission) self.get_files(submission)
self.call_flake(submission) self.call_flake(submission)
@ -45,7 +37,7 @@ class MergeRequests(BaseGitCommand):
source_branch=submission.branch, source_branch=submission.branch,
target_branch="master", target_branch="master",
title=f"[{submission.branch}] {submission.login}", title=f"[{submission.branch}] {submission.login}",
description=f"```\n{self.get_mail()}\n```", description=f"```\n{submission.get_mail()}\n```",
labels=submission.homework, labels=submission.homework,
remove_source_branch="true", remove_source_branch="true",
assignee_ids=["1772"], assignee_ids=["1772"],

View file

@ -64,7 +64,15 @@ class Parser:
points = Parser.parse_points(mail) points = Parser.parse_points(mail)
submissions.append( submissions.append(
Submission(uco, login, path, points, hw_tag, self.correction) Submission(
uco,
login,
path,
points,
hw_tag,
self.correction,
mail.get_payload(),
)
) )
submissions[-1].set_late_tag(self.deadline) submissions[-1].set_late_tag(self.deadline)

View file

@ -2,6 +2,7 @@
import datetime import datetime
import re
from typing import Dict, List from typing import Dict, List
@ -14,6 +15,7 @@ class Submission:
points: float, points: float,
homework: str, homework: str,
correction: bool, correction: bool,
mail: str,
) -> None: ) -> None:
self.uco = uco self.uco = uco
self.login = login self.login = login
@ -21,6 +23,7 @@ class Submission:
self.points = points self.points = points
self.homework = homework self.homework = homework
self.correction = correction self.correction = correction
self.mail = mail
self.submitted_at = None self.submitted_at = None
self.submitted_before_deadline = None self.submitted_before_deadline = None
@ -38,6 +41,10 @@ class Submission:
if not self.submitted_before_deadline: if not self.submitted_before_deadline:
self.flag = "LATE" self.flag = "LATE"
def get_mail(self) -> str:
match = re.search(r"<pre>((.*\s+)+)<\/pre>", self.mail)
return match.group(1) if match else self.mail
def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None: def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None:
header = ( header = (