From a79b3f4319b2d12481a5aa73587c022d1d590a55 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Sat, 30 Nov 2019 22:47:08 +0100 Subject: [PATCH] Mail from mailbox Closes #6 --- commands/merge_requests.py | 12 ++---------- kontr_emails.py | 10 +++++++++- submission.py | 7 +++++++ 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/commands/merge_requests.py b/commands/merge_requests.py index 699e855..651521b 100644 --- a/commands/merge_requests.py +++ b/commands/merge_requests.py @@ -14,7 +14,7 @@ from utils import run_cmd class MergeRequests(BaseGitCommand): @staticmethod 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: exit(1) @@ -25,14 +25,6 @@ class MergeRequests(BaseGitCommand): with open("flake.log", "w") as f: print(process.stdout, file=f) - @staticmethod - def get_mail() -> None: - with open("teacher_email") as file: - contents = file.read() - match = re.search(r"
((.*\s+)+)<\/pre>", contents)
-
-            return match.group(1) if match else contents
-
     def exec(self, submission: Submission) -> None:
         self.get_files(submission)
         self.call_flake(submission)
@@ -45,7 +37,7 @@ class MergeRequests(BaseGitCommand):
             source_branch=submission.branch,
             target_branch="master",
             title=f"[{submission.branch}] {submission.login}",
-            description=f"```\n{self.get_mail()}\n```",
+            description=f"```\n{submission.get_mail()}\n```",
             labels=submission.homework,
             remove_source_branch="true",
             assignee_ids=["1772"],
diff --git a/kontr_emails.py b/kontr_emails.py
index bd1a3fa..029e21a 100644
--- a/kontr_emails.py
+++ b/kontr_emails.py
@@ -64,7 +64,15 @@ class Parser:
             points = Parser.parse_points(mail)
 
             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)
 
diff --git a/submission.py b/submission.py
index 38eda85..022a5be 100644
--- a/submission.py
+++ b/submission.py
@@ -2,6 +2,7 @@
 
 
 import datetime
+import re
 from typing import Dict, List
 
 
@@ -14,6 +15,7 @@ class Submission:
         points: float,
         homework: str,
         correction: bool,
+        mail: str,
     ) -> None:
         self.uco = uco
         self.login = login
@@ -21,6 +23,7 @@ class Submission:
         self.points = points
         self.homework = homework
         self.correction = correction
+        self.mail = mail
 
         self.submitted_at = None
         self.submitted_before_deadline = None
@@ -38,6 +41,10 @@ class Submission:
         if not self.submitted_before_deadline:
             self.flag = "LATE"
 
+    def get_mail(self) -> str:
+        match = re.search(r"
((.*\s+)+)<\/pre>", self.mail)
+        return match.group(1) if match else self.mail
+
 
 def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None:
     header = (