Commit c0dc0426 authored by Jakob Marten's avatar Jakob Marten
Browse files

Added git helper

parent c830cc47
......@@ -25,6 +25,11 @@ LDAP_PASSWORD = None
LDAP_MAIL = None
LDAP_NAME = None
GIT_REPO = 'git@git.finf.uni-hannover.de:jfmarten/test'
GIT_REPO_NAME = 'test'
GIT_NAME = 'Jakob Marten'
GIT_EMAIL = 'marten@finf.uni-hannover.de'
@dataclass
class Gremium:
......@@ -77,21 +82,64 @@ def sendFRMail(text: str, subject: str, sender: MailParticipant, receivers: List
with open(attachement.compiledPath, "rb") as d:
payload.set_payload(d.read())
encoders.encode_base64(payload)
payload.add_header('Content-Disposition', f"attachment; filename={attachement.displayName}")
payload.add_header('Content-Disposition',
f"attachment; filename={attachement.displayName}")
mail.attach(payload)
try:
server = smtplib.SMTP("mail.finf.uni-hannover.de", 587)
server.starttls()
server.login(sender.mail, LDAP_PASSWORD)
server.sendmail(sender.mail, [r.mail for r in receivers], mail.as_string())
server.sendmail(
sender.mail, [r.mail for r in receivers], mail.as_string())
server.quit()
print(f"Email \"{subject}\" an {receivers} erfolgreich versendet")
except smtplib.SMTPException:
print(f"Fehler beim Senden der Email \"{subject}\" von {sender} an {receivers}")
print(
f"Fehler beim Senden der Email \"{subject}\" von {sender} an {receivers}")
raise
# === Git Helper ===
class GitHelper:
def __init__(self, repository, repository_name):
self.repository = repository
self.repository_name = self.repository_name
def clone(self):
cmd = f'git clone {self.repository}'
os.system(cmd)
def pull(self):
cmd = f'git -C {self.repository_name} pull origin master'
os.system(cmd)
def update(self):
if os.path.exists(self.repository_name+"/.git"):
self.pull()
else:
self.clone()
def push(self):
cmd = f'git -C {self.repository_name} push origin master'
os.system(cmd)
def add(self, file):
cmd = f'git -C {self.repository_name} add {file}'
os.system(cmd)
def commit(self, msg):
cmd = f'git -C {self.repository_name} commit -m {msg}'
os.system(cmd)
def config(self, email, name):
cmd = f'git -C {self.repository_name} config user.name {name}'
os.system(cmd)
cmd = f'git -C {self.repository_name} config user.email {email}'
os.system(cmd)
# === Source Types ===
class SourceTypes:
def __init__(self, url: str):
......@@ -160,7 +208,9 @@ class BasePad:
outFilePath = self.DEFAULT_COMPILED_PATH()
outPath = Path(outFilePath)
os.makedirs(outPath.parent, exist_ok=True)
metadataStr = " " + " ".join([f'-M {key}="{val}"' for key, val in self.metadata.items()])
metadataStr = " " + \
" ".join([f'-M {key}="{val}"' for key,
val in self.metadata.items()])
templateStr = ""
if template is None and hasattr(self, "gremium"):
templateStr = f' --template="{getattr(self, "gremium").fullTemplate()}" '
......@@ -226,11 +276,16 @@ class ProtocolPad(BasePad):
return False
return True
def uploadToCloud(self) -> bool:
def uploadToCloud(self):
pass
def uploadToGrav(self) -> bool:
pass
def uploadToGrav(self):
gitHelper = GitHelper(GIT_REPO, GIT_REPO_NAME)
gitHelper.update()
gitHelper.config(GIT_EMAIL, GIT_NAME)
gitHelper.add()
gitHelper.commit("Added protocol ("+self.date+")")
class AttachementPad(BasePad):
......@@ -294,7 +349,8 @@ class PadCollection(BasePad):
padType = ProtocolPad
kwargs["isApproved"] = isApproved
try:
date = datetime.datetime.strptime(comment[0].strip(), "%d.%m.%Y")
date = datetime.datetime.strptime(
comment[0].strip(), "%d.%m.%Y")
except Exception:
dateStr = url.split("protokoll")[-1][:8]
date = datetime.datetime.strptime(dateStr, "%Y%m%d")
......@@ -308,7 +364,8 @@ class PadCollection(BasePad):
if __name__ == '__main__':
import argparse
parser = argparse.ArgumentParser(description="Download and convert finf/fsr-protocols using pandoc")
parser = argparse.ArgumentParser(
description="Download and convert finf/fsr-protocols using pandoc")
parser.add_argument("-urls", nargs="+", type=str, default=[])
parser.add_argument("-pad", type=str, default=None)
# parser.add_argument("--prefixes", type=str, default="",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment