Globbing
This commit is contained in:
parent
1e74e27b6a
commit
37b4d04d11
9 changed files with 67 additions and 49 deletions
|
@ -11,8 +11,9 @@ from submission import Submission
|
||||||
|
|
||||||
|
|
||||||
class BaseCommand:
|
class BaseCommand:
|
||||||
def __init__(self, submissions: List[Submission], gitlab: Gitlab, details:
|
def __init__(
|
||||||
Dict) -> None:
|
self, submissions: List[Submission], gitlab: Gitlab, details: Dict
|
||||||
|
) -> None:
|
||||||
self.submissions = submissions
|
self.submissions = submissions
|
||||||
self.gitlab = gitlab
|
self.gitlab = gitlab
|
||||||
self.hw = details
|
self.hw = details
|
||||||
|
|
|
@ -21,7 +21,9 @@ class Comments(BaseCommand):
|
||||||
if author not in result:
|
if author not in result:
|
||||||
result[author] = dict()
|
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]:
|
if file_path not in result[author]:
|
||||||
result[author][file_path] = list()
|
result[author][file_path] = list()
|
||||||
|
|
||||||
|
@ -30,9 +32,11 @@ class Comments(BaseCommand):
|
||||||
# sort by lines
|
# sort by lines
|
||||||
for author in result:
|
for author in result:
|
||||||
for file_path in result[author]:
|
for file_path in result[author]:
|
||||||
result[author][file_path].sort(key=lambda comment:
|
result[author][file_path].sort(
|
||||||
comment["position"]["new_line"] if "position" in comment
|
key=lambda comment: comment["position"]["new_line"]
|
||||||
else math.inf)
|
if "position" in comment
|
||||||
|
else math.inf
|
||||||
|
)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
|
|
||||||
|
import glob
|
||||||
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
@ -12,14 +14,22 @@ from utils import run_cmd
|
||||||
|
|
||||||
class MergeRequests(BaseGitCommand):
|
class MergeRequests(BaseGitCommand):
|
||||||
def get_files(self, submission: Submission) -> None:
|
def get_files(self, submission: Submission) -> None:
|
||||||
files = f"{self.hw['prefix']}/"
|
files = []
|
||||||
if len(self.hw['files']) > 1:
|
for file in self.hw["files"]:
|
||||||
files += f"{{{','.join(self.hw['files'])}}}"
|
files.extend(glob.glob(f'{submission.path}/{self.hw["prefix"]}/{file}'))
|
||||||
else:
|
files = map(lambda f: f.split("/")[-1], files)
|
||||||
files += f"{self.hw['files'][0]}"
|
|
||||||
|
|
||||||
if run_cmd("rsync", "-avzP", f"aisa:{submission.path}/{files}", "./")[0] != 0:
|
for file in files:
|
||||||
exit(1)
|
if (
|
||||||
|
run_cmd(
|
||||||
|
"rsync",
|
||||||
|
"-avzP",
|
||||||
|
f"aisa:{submission.path}/{self.hw['prefix']}/{file}",
|
||||||
|
"./",
|
||||||
|
)[0]
|
||||||
|
!= 0
|
||||||
|
):
|
||||||
|
exit(1)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def call_flake(submission: Submission) -> None:
|
def call_flake(submission: Submission) -> None:
|
||||||
|
@ -31,18 +41,21 @@ class MergeRequests(BaseGitCommand):
|
||||||
self.get_files(submission)
|
self.get_files(submission)
|
||||||
# self.call_flake(submission)
|
# self.call_flake(submission)
|
||||||
|
|
||||||
add_files(*self.hw['files'])
|
add_files(*self.hw["files"])
|
||||||
commit(f'"Add sources ({submission.branch} {submission.login})"')
|
commit(f'"Add sources ({submission.branch} {submission.login})"')
|
||||||
push("origin", submission.branch)
|
push("origin", submission.branch)
|
||||||
|
|
||||||
mail = f"<details>\n<summary>Mail</summary>\n\n<pre>{submission.get_mail()}</pre></details>"
|
mail = f"<details>\n<summary>Mail</summary>\n\n<pre>{submission.get_mail()}</pre></details>"
|
||||||
|
|
||||||
self.gitlab.post_mr(
|
try:
|
||||||
source_branch=submission.branch,
|
self.gitlab.post_mr(
|
||||||
target_branch="master",
|
source_branch=submission.branch,
|
||||||
title=f"[{submission.homework}{'-opravne' if submission.correction else ''}] {submission.login}",
|
target_branch="master",
|
||||||
description=mail,
|
title=f"[{submission.homework}{'-opravne' if submission.correction else ''}] {submission.login}",
|
||||||
labels=submission.homework,
|
description=mail,
|
||||||
remove_source_branch="true",
|
labels=submission.homework,
|
||||||
assignee_ids=["1772"],
|
remove_source_branch="true",
|
||||||
)
|
assignee_ids=["1772"],
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
3
git.py
3
git.py
|
@ -11,7 +11,8 @@ def checkout_branch(branch: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def add_files(*files: str) -> None:
|
def add_files(*files: str) -> None:
|
||||||
run_cmd("git", "add", *files)
|
for f in files:
|
||||||
|
run_cmd("git", "add", f)
|
||||||
|
|
||||||
|
|
||||||
def commit(msg: str) -> None:
|
def commit(msg: str) -> None:
|
||||||
|
|
|
@ -7,13 +7,9 @@ from ogr.services.gitlab import GitlabService
|
||||||
class Gitlab:
|
class Gitlab:
|
||||||
def __init__(self, namespace, repo, token):
|
def __init__(self, namespace, repo, token):
|
||||||
self.ogr_service = GitlabService(
|
self.ogr_service = GitlabService(
|
||||||
token=token,
|
token=token, instance_url="https://gitlab.fi.muni.cz"
|
||||||
instance_url="https://gitlab.fi.muni.cz"
|
|
||||||
)
|
|
||||||
self.ogr_project = self.ogr_service.get_project(
|
|
||||||
repo=repo,
|
|
||||||
namespace=namespace
|
|
||||||
)
|
)
|
||||||
|
self.ogr_project = self.ogr_service.get_project(repo=repo, namespace=namespace)
|
||||||
|
|
||||||
def post_mr(
|
def post_mr(
|
||||||
self,
|
self,
|
||||||
|
@ -29,7 +25,7 @@ class Gitlab:
|
||||||
title=title,
|
title=title,
|
||||||
body=description,
|
body=description,
|
||||||
target_branch=target_branch,
|
target_branch=target_branch,
|
||||||
source_branch=source_branch
|
source_branch=source_branch,
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_mrs_for_branch(self, branch):
|
def get_mrs_for_branch(self, branch):
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Parser:
|
||||||
def get_mail(mail: mboxMessage) -> str:
|
def get_mail(mail: mboxMessage) -> str:
|
||||||
body = None
|
body = None
|
||||||
for payload in mail.get_payload():
|
for payload in mail.get_payload():
|
||||||
if payload['Content-Type'].startswith('text/html'):
|
if payload["Content-Type"].startswith("text/html"):
|
||||||
body = payload.get_payload()
|
body = payload.get_payload()
|
||||||
|
|
||||||
return body
|
return body
|
||||||
|
@ -63,7 +63,9 @@ class Parser:
|
||||||
self.box = mbox(details["mbox_path"])
|
self.box = mbox(details["mbox_path"])
|
||||||
self.reviewer = reviewer
|
self.reviewer = reviewer
|
||||||
|
|
||||||
self.deadline = datetime.datetime.strptime(details["deadline"], Parser.DATE_FORMAT)
|
self.deadline = datetime.datetime.strptime(
|
||||||
|
details["deadline"], Parser.DATE_FORMAT
|
||||||
|
)
|
||||||
self.correction = details["correction"]
|
self.correction = details["correction"]
|
||||||
if self.correction:
|
if self.correction:
|
||||||
# in case of correction pass the date of
|
# in case of correction pass the date of
|
||||||
|
@ -76,11 +78,14 @@ class Parser:
|
||||||
if self.from_ids:
|
if self.from_ids:
|
||||||
print(self.submissions)
|
print(self.submissions)
|
||||||
for submission_id in self.submissions:
|
for submission_id in self.submissions:
|
||||||
with open(f'/home/kontr/kontr/_tmp_/pb071/{self.homework}/{submission_id}/teacher_email', 'r') as f:
|
with open(
|
||||||
|
f"/home/kontr/kontr/_tmp_/pb071/{self.homework}/{submission_id}/teacher_email",
|
||||||
|
"r",
|
||||||
|
) as f:
|
||||||
mails.append(f.read())
|
mails.append(f.read())
|
||||||
else:
|
else:
|
||||||
for mail in self.box.values():
|
for mail in self.box.values():
|
||||||
if self.reviewer not in mail['subject']:
|
if self.reviewer not in mail["subject"]:
|
||||||
continue
|
continue
|
||||||
mails.append(Parser.get_mail(mail))
|
mails.append(Parser.get_mail(mail))
|
||||||
|
|
||||||
|
@ -167,4 +172,3 @@ class Parser:
|
||||||
for something in submissions.values():
|
for something in submissions.values():
|
||||||
functools.reduce(__reducer, something, result)
|
functools.reduce(__reducer, something, result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
14
pushee.py
14
pushee.py
|
@ -54,13 +54,15 @@ def main():
|
||||||
|
|
||||||
details = config["homeworks"][config["homework"]]
|
details = config["homeworks"][config["homework"]]
|
||||||
|
|
||||||
submissions = Parser(
|
submissions = Parser(details, config["reviewer"], config["homework"]).parse(
|
||||||
details, config["reviewer"], config["homework"]
|
config["homework"]
|
||||||
).parse(config["homework"])
|
)
|
||||||
|
|
||||||
COMMANDS[sys.argv[1]](submissions, Gitlab(config["project_namespace"],
|
COMMANDS[sys.argv[1]](
|
||||||
config["project_name"],
|
submissions,
|
||||||
config["token"]), details)()
|
Gitlab(config["project_namespace"], config["project_name"], config["token"]),
|
||||||
|
details,
|
||||||
|
)()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
|
@ -7,7 +7,7 @@ from typing import Dict, List
|
||||||
|
|
||||||
|
|
||||||
class Submission:
|
class Submission:
|
||||||
MAIL_CONTENT= re.compile(r"<pre>((.*\s+)+)<\/pre>")
|
MAIL_CONTENT = re.compile(r"<pre>((.*\s+)+)<\/pre>")
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
|
@ -48,10 +48,7 @@ class Submission:
|
||||||
def get_mail(self) -> str:
|
def get_mail(self) -> str:
|
||||||
left = self.mail.find("<pre>")
|
left = self.mail.find("<pre>")
|
||||||
right = self.mail.rfind("</pre>")
|
right = self.mail.rfind("</pre>")
|
||||||
return self.mail[left + 5:right]
|
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
|
|
||||||
|
|
||||||
|
|
||||||
def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None:
|
def print_submissions(all_submissions: Dict[str, List[Submission]]) -> None:
|
||||||
|
|
4
utils.py
4
utils.py
|
@ -17,11 +17,11 @@ def handle_error(process: CompletedProcess) -> int:
|
||||||
return process.returncode
|
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:
|
if DRY_RUN:
|
||||||
print(" ".join(args))
|
print(" ".join(args))
|
||||||
return (0, None)
|
return (0, None)
|
||||||
process = run(args, capture_output=True)
|
process = run(args, capture_output=True, shell=shell)
|
||||||
return (handle_error(process), process)
|
return (handle_error(process), process)
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue