diff --git a/commands/base.py b/commands/base.py
index d1e20d0..c86dd3a 100644
--- a/commands/base.py
+++ b/commands/base.py
@@ -11,8 +11,9 @@ from submission import Submission
class BaseCommand:
- def __init__(self, submissions: List[Submission], gitlab: Gitlab, details:
- Dict) -> None:
+ def __init__(
+ self, submissions: List[Submission], gitlab: Gitlab, details: Dict
+ ) -> None:
self.submissions = submissions
self.gitlab = gitlab
self.hw = details
diff --git a/commands/comments.py b/commands/comments.py
index 816a3a2..67c1aa3 100644
--- a/commands/comments.py
+++ b/commands/comments.py
@@ -21,7 +21,9 @@ class Comments(BaseCommand):
if author not in result:
result[author] = dict()
- file_path = comment["position"]["new_path"] if "position" in comment else None
+ file_path = (
+ comment["position"]["new_path"] if "position" in comment else None
+ )
if file_path not in result[author]:
result[author][file_path] = list()
@@ -30,9 +32,11 @@ class Comments(BaseCommand):
# sort by lines
for author in result:
for file_path in result[author]:
- result[author][file_path].sort(key=lambda comment:
- comment["position"]["new_line"] if "position" in comment
- else math.inf)
+ result[author][file_path].sort(
+ key=lambda comment: comment["position"]["new_line"]
+ if "position" in comment
+ else math.inf
+ )
return result
diff --git a/commands/merge_requests.py b/commands/merge_requests.py
index a251e55..fd7b3be 100644
--- a/commands/merge_requests.py
+++ b/commands/merge_requests.py
@@ -1,6 +1,8 @@
#!/usr/bin/env python3
+import glob
+import os
import re
@@ -12,14 +14,22 @@ from utils import run_cmd
class MergeRequests(BaseGitCommand):
def get_files(self, submission: Submission) -> None:
- files = f"{self.hw['prefix']}/"
- if len(self.hw['files']) > 1:
- files += f"{{{','.join(self.hw['files'])}}}"
- else:
- files += f"{self.hw['files'][0]}"
+ files = []
+ for file in self.hw["files"]:
+ files.extend(glob.glob(f'{submission.path}/{self.hw["prefix"]}/{file}'))
+ files = map(lambda f: f.split("/")[-1], files)
- if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0:
- exit(1)
+ for file in files:
+ if (
+ run_cmd(
+ "rsync",
+ "-avzP",
+ f"aisa:{submission.path}/{self.hw['prefix']}/{file}",
+ "./",
+ )[0]
+ != 0
+ ):
+ exit(1)
@staticmethod
def call_flake(submission: Submission) -> None:
@@ -31,18 +41,21 @@ class MergeRequests(BaseGitCommand):
self.get_files(submission)
# self.call_flake(submission)
- add_files(*self.hw['files'])
+ add_files(*self.hw["files"])
commit(f'"Add sources ({submission.branch} {submission.login})"')
push("origin", submission.branch)
mail = f"Mail
\n\n{submission.get_mail()}
((.*\s+)+)<\/pre>") + MAIL_CONTENT = re.compile(r"((.*\s+)+)<\/pre>") def __init__( self, @@ -48,10 +48,7 @@ class Submission: def get_mail(self) -> str: left = self.mail.find("") right = self.mail.rfind("") - return self.mail[left + 5:right] - # print(self.mail) - # match = Submission.MAIL_CONTENT.search(self.mail) - # return match.group(1) if match else self.mail + return self.mail[left + 5 : right] def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None: diff --git a/utils.py b/utils.py index 1f48bc7..c29004b 100644 --- a/utils.py +++ b/utils.py @@ -17,11 +17,11 @@ def handle_error(process: CompletedProcess) -> int: return process.returncode -def run_cmd(*args: str) -> Tuple[int, CompletedProcess]: +def run_cmd(*args: str, shell: bool = False) -> Tuple[int, CompletedProcess]: if DRY_RUN: print(" ".join(args)) return (0, None) - process = run(args, capture_output=True) + process = run(args, capture_output=True, shell=shell) return (handle_error(process), process)