Commit 688bdef5 authored by Jakob Marten's avatar Jakob Marten
Browse files

Added git functions

parent 07047689
.idea/
data/
\ No newline at end of file
data/
__pycache__
\ No newline at end of file
......@@ -25,23 +25,30 @@ 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'
IGNORED_TOPS = ["Anwesende", "Ständiges", "Termine"
"Mitteilungen/Verschiedenes", "Schluss"]
GIT_REPO = None
GIT_REPO_NAME = None
GIT_NAME = None
GIT_EMAIL = None
GIT_HELPER = None
@dataclass
class Gremium:
name: str
fullName: str
template: str
def fullTemplate(self):
return str(Path(os.path.join(TEMPLATE_FOLDER, self.template)).absolute())
GREMIUM_FR = Gremium("finf", "pandoc.finf.tex")
GREMIUM_FSR = Gremium("fsr", "pandoc.fsr.tex")
GREMIUM_FR = Gremium("finf", "Fachrat Informatik", "pandoc.finf.tex")
GREMIUM_FSR = Gremium(
"fsr", "Fachschaftsrat Elektrotechnik und Informatik", "pandoc.fsr.tex")
@dataclass
......@@ -105,7 +112,7 @@ class GitHelper:
def __init__(self, repository, repository_name):
self.repository = repository
self.repository_name = self.repository_name
self.repository_name = repository_name
def clone(self):
cmd = f'git clone {self.repository}'
......@@ -130,7 +137,7 @@ class GitHelper:
os.system(cmd)
def commit(self, msg):
cmd = f'git -C {self.repository_name} commit -m {msg}'
cmd = f'git -C {self.repository_name} commit -m \"{msg}\"'
os.system(cmd)
def config(self, email, name):
......@@ -180,6 +187,7 @@ class BasePad:
self.rawPath = rawPath or hashlib.md5(source.url.encode("utf-8"))
self.displayName = displayName or self.DEFAULT_DISPLAY_NAME()
self.compiledPath = None
self.folder = ""
def __repr__(self):
return f"{self.__class__.__name__}({self.source})"
......@@ -199,6 +207,7 @@ class BasePad:
content = self.source.retrieveContent()
if not override and os.path.exists(path):
raise FileExistsError(f"{path} already exists!")
os.makedirs(str(Path(path).parent), exist_ok=True)
with open(path, "w", encoding="utf-8") as d:
d.write(content)
self.rawPath = path
......@@ -238,6 +247,9 @@ class ProtocolPad(BasePad):
def DEFAULT_DISPLAY_NAME(self):
return f"Protokoll {self.gremium.name} {self.date.strftime('%Y-%m-%d')}" + " - Fachgruppenvollversammlung"*self.isFachgruppenvollversammlung
def DEFAULT_GRAV_PATH(self):
return os.path.join(GIT_REPO_NAME, "pages", "fachrat", "02.protokolle", self.folder, self.date.strftime("%Y-%m-%d")+"-fgvv"*self.isFachgruppenvollversammlung, "default.de.md")
def sendMailAsUnapproved(self) -> bool:
sender = MailParticipant(LDAP_MAIL, LDAP_NAME)
receiver = [
......@@ -280,12 +292,58 @@ class ProtocolPad(BasePad):
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+")")
if not os.path.exists(self.DEFAULT_RAW_PATH()):
raise FileNotFoundError(f"{self.DEFAULT_RAW_PATH()} doesn't exist")
self.rawPath = self.DEFAULT_RAW_PATH()
lines_new = []
with open(self.rawPath, "r", encoding="utf-8") as f:
lines = f.read().split("\n")
tops = []
for l in lines:
if l.startswith("## "):
l = l[3:]
if "(" in l:
l = l[:l.index("(")]
l = l.strip()
if any(l in t or t in l for t in IGNORED_TOPS):
continue
tops.append(l)
header = ""
tops_text = ", ".join(tops)
if self.isFachgruppenvollversammlung:
header = ("---\n"
f"title: Protokoll der Fachgruppenvollversammlung am {self.date.strftime('%d.%m.%Y')}\n"
f"date: {self.date.strftime('%d.%m.%Y')}\n"
f"tops: {tops_text}\n"
"---\n\n"
"[MINITOC]\n\n")
else:
header = ("---\n"
f"title: Protokoll des {self.gremium.fullName} am {self.date.strftime('%d.%m.%Y')}\n"
f"date: {self.date.strftime('%d.%m.%Y')}\n"
f"tops: {tops_text}\n"
"---\n\n"
"[MINITOC]\n\n")
lines_new.append(header)
ignore = False
for l in lines:
if l.startswith("######"):
continue
if l == "---":
ignore = True
continue
if l == "...":
ignore = False
continue
if ignore:
continue
lines_new.append(l)
os.makedirs(str(Path(self.DEFAULT_GRAV_PATH()).parent), exist_ok=True)
with open(self.DEFAULT_GRAV_PATH(), "w", encoding="utf-8") as f:
f.write("\n".join(lines_new))
GIT_HELPER.add("pages/")
GIT_HELPER.commit(f"Added protocol {self.DEFAULT_DISPLAY_NAME()}")
GIT_HELPER.push()
class AttachementPad(BasePad):
......@@ -319,6 +377,7 @@ class PadCollection(BasePad):
continue
if currentFolder not in pads:
pads[currentFolder] = list()
pad.folder = currentFolder
pads[currentFolder].append(pad)
return pads
......@@ -364,6 +423,15 @@ class PadCollection(BasePad):
return padType(src, **kwargs)
def initGit():
global GIT_HELPER
if GIT_REPO == None or GIT_REPO_NAME == None or GIT_EMAIL == None or GIT_NAME != None:
raise RuntimeError("Git is not configured correctly")
GIT_HELPER = GitHelper(GIT_REPO, GIT_REPO_NAME)
GIT_HELPER.config(GIT_EMAIL, GIT_NAME)
GIT_HELPER.update()
if __name__ == '__main__':
import argparse
......
......@@ -5,10 +5,10 @@ import linkToPDF2 as pter
class ProtokollGUI(tk.Tk):
def __init__(self, rootPad:pter.SourceTypes):
def __init__(self, rootPad: pter.SourceTypes):
super().__init__(screenName="ProtokollHelper")
self.rootPad = pter.PadCollection(rootPad)
print(self.rootPad.getPads())
# print(self.rootPad.getPads())
self.folders = dict()
self.folderIndex = 0
......@@ -18,8 +18,10 @@ 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)
......@@ -31,7 +33,7 @@ class ProtokollGUI(tk.Tk):
self.updatePadFrame()
def updateFolderIndex(self, i):
def wrapper(*args,**kwargs):
def wrapper(*args, **kwargs):
self.folderIndex = (self.folderIndex + i) % len(self.folders)
self.updatePadFrame()
......@@ -40,42 +42,49 @@ 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.sendMailAsUnapproved)
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", state=tk.DISABLED, command=pad.uploadToGrav)
btnWebsite = tk.Button(
self.padFrame, text="Approved Website", 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"))
gui = ProtokollGUI(pter.CodiMD("https://pad.finf.uni-hannover.de/protokolllinks_terces"))
pter.DEFAULT_GREMIUM = pter.GREMIUM_FR
pter.initGit()
gui = ProtokollGUI(pter.CodiMD(
"https://pad.finf.uni-hannover.de/protokolllinks_terces"))
gui.mainloop()
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