Commit a1708fbf authored by Dominik Woiwode's avatar Dominik Woiwode
Browse files

Move classes in separate file. Move config

parent b903c6ee
import pterClasses
from pterClasses import MailParticipant
class Config:
NOT_APPROVED_SIGN = "*"
ATTACHMENT_SIGN = "+"
FACHGRUPPENVOLLVERSAMMLUNG_SIGN = ">"
# Folders
TEMPLATE_FOLDER = "templates"
DATA_FOLDER = "data"
OVERRIDE_ACCEPTED = False
GREMIUM = None
PAD_COLLECTION_URL = None
# LDAP
LDAP_USER = ""
LDAP_PASSWORD = ""
LDAP_MAIL = ""
MAIL_DISPLAY_NAME = ""
APPROVED_MAIL_RECEIVER = [MailParticipant("fr-info@finf.uni-hannover.de", "FR-Info")]
PRELIMINARY_MAIL_RECEIVER = [MailParticipant("fr@finf.uni-hannover.de", "Fachrat Informatik Hannover")]
# Grav
GRAV_PROTOCOL_PATH = "pages/fachrat/02.protokolle/"
IGNORED_TOPS = ["Anwesende", "Ständiges", "Termine", "Mitteilungen/Verschiedenes", "Schluss"]
# Git
GIT_REPO = "https://git.finf.uni-hannover.de/fachrat-informatik/website.git"
GIT_REPO_PATH = "gravRepo"
GIT_NAME = "pter"
GIT_EMAIL = ""
# Properties
_git = None
@property
def git(self):
if self._git is not None:
return self._git
if any(o is None for o in [self.GIT_REPO, self.GIT_REPO_PATH, self.GIT_EMAIL, self.GIT_NAME]):
raise RuntimeError("Git is not configured correctly")
self._git = pterClasses.GitHelper(self.GIT_REPO, self.GIT_REPO_PATH)
self._git.config(self.GIT_EMAIL, self.GIT_NAME)
self._git.update()
return self._git
This diff is collapsed.
import tkinter as tk
from functools import wraps
import config
import linkToPDF2 as pter
import pterClasses
class ProtokollGUI(tk.Tk):
def __init__(self, rootPad: pter.SourceTypes):
def __init__(self, opt: config.Config):
super().__init__(screenName="ProtokollHelper")
self.rootPad = pter.PadCollection(rootPad)
# print(self.rootPad.getPads())
self.opt = opt
self.rootPad = pter.PadCollection(pter.CodiMD(self.opt.PAD_COLLECTION_URL))
self.folders = dict()
self.folderIndex = 0
......@@ -18,10 +20,8 @@ class ProtokollGUI(tk.Tk):
self.topRow = tk.Frame(self)
self.topRow.pack(fill=tk.X, expand=True)
self.folderLabel = tk.Label(self.topRow)
self.leftButton = tk.Button(
self.topRow, text="<", state=tk.DISABLED, command=self.updateFolderIndex(-1))
self.rightButton = tk.Button(
self.topRow, text=">", command=self.updateFolderIndex(1))
self.leftButton = tk.Button(self.topRow, text="<", state=tk.DISABLED, command=self.updateFolderIndex(-1))
self.rightButton = tk.Button(self.topRow, text=">", command=self.updateFolderIndex(1))
self.leftButton.pack(side=tk.LEFT)
self.folderLabel.pack(side=tk.LEFT, fill=tk.X, expand=True)
......@@ -33,6 +33,7 @@ class ProtokollGUI(tk.Tk):
self.updatePadFrame()
def updateFolderIndex(self, i):
@wraps(self.updateFolderIndex)
def wrapper(*args, **kwargs):
self.folderIndex = (self.folderIndex + i) % len(self.folders)
self.updatePadFrame()
......@@ -42,49 +43,39 @@ class ProtokollGUI(tk.Tk):
def updatePadFrame(self):
folderName = list(self.folders.keys())[self.folderIndex]
self.folderLabel.configure(text=folderName)
self.currentPads = [p for p in self.folders[folderName]
if isinstance(p, pter.ProtocolPad)]
self.currentPads = [p for p in self.folders[folderName] if isinstance(p, pter.ProtocolPad)]
for i, pad in enumerate(self.currentPads):
assert isinstance(pad, pter.ProtocolPad)
tk.Label(self.padFrame, text=pad.source.url, anchor=tk.W,
bg="red").grid(row=i, column=0, sticky=tk.W) # URL
tk.Label(self.padFrame, text=pad.date, anchor=tk.W,
bg="blue").grid(row=i, column=1) # Date
tk.Label(self.padFrame, text=pad.source.url, anchor=tk.W, bg="red").grid(row=i, column=0,
sticky=tk.W) # URL
tk.Label(self.padFrame, text=pad.date, anchor=tk.W, bg="blue").grid(row=i, column=1) # Date
# Button Download
btnDownload = tk.Button(
self.padFrame, text="Download", command=pad.download)
btnDownload = tk.Button(self.padFrame, text="Download", command=pad.download)
btnDownload.grid(row=i, column=2)
# Button Compile
btnCompile = tk.Button(
self.padFrame, text="Compile", command=pad.compile)
btnCompile = tk.Button(self.padFrame, text="Compile", command=pad.compile)
btnCompile.grid(row=i, column=3)
# Button Mail FR
btnMailFR = tk.Button(
self.padFrame, text="Vorläufige FR-Mail", command=pad.sendMailAsUnapproved)
btnMailFR = tk.Button(self.padFrame, text="Vorläufige FR-Mail", command=pad.sendMailAsPreliminary)
btnMailFR.grid(row=i, column=4)
# Button Mail FR-Info
btnMailFRInfo = tk.Button(
self.padFrame, text="FR-Info Mail", state=tk.DISABLED, command=pad.sendMailAsApproved)
btnMailFRInfo = tk.Button(self.padFrame, text="FR-Info Mail", state=tk.DISABLED,
command=pad.sendMailAsApproved)
btnMailFRInfo.grid(row=i, column=5)
# Button Website
btnWebsite = tk.Button(
self.padFrame, text="Approved Website", command=pad.uploadToGrav)
btnWebsite = tk.Button(self.padFrame, text="Approved Website", state=tk.DISABLED, command=pad.uploadToGrav)
btnWebsite.grid(row=i, column=6)
# Button Cloud
btnCloud = tk.Button(self.padFrame, text="Approved Cloud",
state=tk.DISABLED, command=pad.uploadToCloud)
btnCloud = tk.Button(self.padFrame, text="Approved Cloud", state=tk.DISABLED, command=pad.uploadToCloud)
btnCloud.grid(row=i, column=7)
if __name__ == '__main__':
# gui = ProtokollGUI(pter.LocalCache("data/rootPad.md"))
pter.DEFAULT_GREMIUM = pter.GREMIUM_FR
pter.initGit()
gui = ProtokollGUI(pter.CodiMD(
"https://pad.finf.uni-hannover.de/protokolllinks_terces"))
pter.opt.GREMIUM = pterClasses.GREMIUM_FR
gui = ProtokollGUI(pter.opt)
gui.mainloop()
import os
import smtplib
from dataclasses import dataclass
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from enum import Enum
from pathlib import Path
from typing import List
@dataclass
class Gremium:
name: str
fullName: str
template: str
def fullTemplate(self):
from linkToPDF2 import opt
return str(Path(os.path.join(opt.TEMPLATE_FOLDER, self.template)).absolute())
GREMIUM_FR = Gremium("finf", "Fachrat Informatik", "pandoc.finf.tex")
GREMIUM_FSR = Gremium("fsr", "Fachschaftsrat Elektrotechnik und Informatik", "pandoc.fsr.tex")
@dataclass
class MailParticipant:
mail: str
alias: str = None
def __post_init__(self):
self.alias = self.mail
def __str__(self):
return f"{self.alias} <{self.mail}>"
@staticmethod
def FR_INFO():
return MailParticipant("fr-info@finf.uni-hannover.de", "FR-Info")
@staticmethod
def FR():
return MailParticipant("fr@finf.uni-hannover.de", "Fachrat Informatik")
def sendFRMail(text: str, subject: str, sender: MailParticipant, receivers: List[MailParticipant],
attachment: "BasePad" = None, *_, ldapPassword=None):
if ldapPassword is None:
raise ValueError("Require ldapPassword")
mail = MIMEMultipart()
mail['Content-transfer-encoding'] = '8bit'
mail['From'] = sender.alias
mail['Subject'] = subject
receiveralias = ", ".join([r.alias for r in receivers])
mail['To'] = receiveralias
msg = MIMEText(text, "plain", "utf-8")
mail.attach(msg)
if attachment is not None:
payload = MIMEBase('application', 'octet-stream')
with open(str(attachment.compiledPath), "rb") as d:
payload.set_payload(d.read())
encoders.encode_base64(payload)
payload.add_header('Content-Disposition',
f"attachment; filename=\"{attachment.displayName}.pdf\"")
mail.attach(payload)
try:
server = smtplib.SMTP("mail.finf.uni-hannover.de", 587)
server.starttls()
server.login(sender.mail, ldapPassword)
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}")
raise
class GitHelper:
def __init__(self, repository: str, repository_path: str):
self.repository = repository
self.repository_path = repository_path
def config(self, email, name):
cmd = f'git -C {self.repository_path} config user.name {name}'
os.system(cmd)
cmd = f'git -C {self.repository_path} config user.email {email}'
os.system(cmd)
def clone(self):
cmd = f'git clone {self.repository} {self.repository_path}'
os.system(cmd)
def forcePull(self):
cmd = f'git -C {self.repository_path} fetch origin master'
os.system(cmd)
cmd = f'git -C {self.repository_path} reset --hard origin/master'
os.system(cmd)
def update(self):
if os.path.exists(os.path.join(self.repository_path, "/.git")):
self.forcePull()
else:
self.clone()
def add(self, file: str):
cmd = f'git -C {self.repository_path} add {file}'
os.system(cmd)
def commit(self, msg: str):
cmd = f'git -C {self.repository_path} commit -m \"{msg}\"'
os.system(cmd)
def push(self):
cmd = f'git -C {self.repository_path} push origin master'
os.system(cmd)
class SemesterPart(Enum):
Summer = "Sommersemester"
Winter = "Wintersemester"
def short(self):
if self == SemesterPart.Summer:
return "SS"
elif self == SemesterPart.Winter:
return "WS"
raise ValueError("Unknown Semesterpart")
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