Commit 50bf8f3d authored by dwoiwode's avatar dwoiwode
Browse files

Fix Merge error and further style cleanup

parent 18082c41
import datetime
import hashlib
import os
import subprocess
from dataclasses import dataclass
......@@ -9,9 +8,9 @@ from typing import Optional, Dict, List, Iterator, Tuple
import requests
import config
from pterClasses import Gremium, GREMIUM_FR, GREMIUM_FSR, MailParticipant, sendFRMail, SemesterPart
from pterClasses import Gremium, GREMIUM_FR, GREMIUM_FSR, MailParticipant, send_fr_mail, SemesterPart
import config
opt = config.Config()
......@@ -22,7 +21,8 @@ class Semester:
def __post_init__(self):
self.display_name = f"{self.part.value} {self.year}"
self.grav_path = Path(opt.GIT_REPO_PATH) / opt.GRAV_PROTOCOL_PATH / self._grav_name() / "protocol_semester.de.md"
self.grav_path = Path(
opt.GIT_REPO_PATH) / opt.GRAV_PROTOCOL_PATH / self._grav_name() / "protocol_semester.de.md"
def _grav_name(self):
return f"{self.year - 2000}{self.part.short()}"
......@@ -150,15 +150,15 @@ class BasePad:
return self.source.url
@property
def rawPath(self) -> Path:
def raw_path(self) -> Path:
return Path(opt.DATA_FOLDER).absolute() / "raw" / f"{self.display_name}.md"
@property
def compiledPath(self) -> Path:
def compiled_path(self) -> Path:
return Path(opt.DATA_FOLDER).absolute() / "result" / f"{self.display_name}.pdf"
def download(self, override=True):
content = self.source.retrieveContent()
content = self.source.retrieve_content()
if not override and self.raw_path.exists():
raise FileExistsError(f"{self.raw_path} already exists!")
self.raw_path.parent.mkdir(parents=True, exist_ok=True)
......@@ -166,9 +166,8 @@ class BasePad:
d.write(content)
self.source = LocalCache(self.source.url, str(self.raw_path))
def compile(self, template: str = None) -> int:
self.compiledPath.parent.mkdir(parents=True, exist_ok=True)
def compile_(self, template: str = None) -> int:
self.compiled_path.parent.mkdir(parents=True, exist_ok=True)
metadata = [f'-M {key}="{val}"' for key, val in self.metadata.items()]
if template is None and hasattr(self, "gremium"):
template = getattr(self, "gremium").full_template()
......@@ -211,15 +210,15 @@ class ProtocolPad(BasePad):
# TODO: better top filter?
lines = self.source.retrieve_content().split("\n")
tops = []
for l in lines:
for line in lines:
# TODO: Change to regex?
# import re
# res = re.match("^## ([\w\d &!\"'§$%/\-+äöüß]+)\w*(\(\d\d:\d\d Uhr\))?", l)
# res = re.match("^## ([\w\d &!\"'§$%/\-+äöüß]+)\w*(\(\d\d:\d\d Uhr\))?", line)
# if res is not None:
# top = res.group(1)
if l.startswith("## "):
top = l.strip("#").rsplit("(")[0].strip()
if line.startswith("## "):
top = line.strip("#").rsplit("(")[0].strip()
if any(top in t or t in top for t in opt.IGNORED_TOPS):
continue
tops.append(top)
......@@ -228,18 +227,18 @@ class ProtocolPad(BasePad):
def cleaned_raw(self):
lines_new = []
ignore = False
for l in self.source.retrieve_content().split("\n"):
if l.startswith("######"): # tags 'fr'
for line in self.source.retrieve_content().split("\n"):
if line.startswith("######"): # tags 'fr'
continue
if l == "---":
if line == "---":
ignore = True
continue
if l == "...":
if line == "...":
ignore = False
continue
if ignore:
continue
lines_new.append(l)
lines_new.append(line)
return "\n".join(lines_new)
def send_mail_as_preliminary(self) -> bool:
......@@ -391,12 +390,12 @@ class PadCollection(BasePad):
url = f"https://{url}".strip()
if Etherpad.fit_url(url):
retrieveClass = CachedEtherPad
retrieve_class = CachedEtherPad
elif CodiMD.fit_url(url):
retrieveClass = CachedCodiMD
retrieve_class = CachedCodiMD
else:
raise ValueError("Cannot retrieve SourceType class")
src = retrieveClass(url)
src = retrieve_class(url)
is_attachement = opt.ATTACHMENT_SIGN in all_prefixes
is_fachgrupenvollversammlung = opt.FACHGRUPPENVOLLVERSAMMLUNG_SIGN in all_prefixes
......@@ -404,24 +403,24 @@ class PadCollection(BasePad):
kwargs = dict()
if is_attachement:
padType = AttachementPad
pad_type = AttachementPad
kwargs["date"] = None
kwargs["name"] = None
kwargs["version"] = None
kwargs["is_approved"] = is_approved
else:
padType = ProtocolPad
pad_type = ProtocolPad
kwargs["is_approved"] = is_approved
try:
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")
date_str = url.split("protokoll")[-1][:8]
date = datetime.datetime.strptime(date_str, "%Y%m%d")
kwargs["date"] = date
kwargs["is_fachgruppenvollversammlung"] = is_fachgrupenvollversammlung
return padType(src, **kwargs)
return pad_type(src, **kwargs)
def remove_approved(self):
old_pads = self.pads
......@@ -452,16 +451,15 @@ class PadCollection(BasePad):
def compile_pads(self, template: str = None):
for folder, pad in self:
pad.compile(template)
pad.compile_(template)
def create_topics(self):
raise NotImplementedError()
if __name__ == '__main__':
def main():
import argparse
opt = config.Config()
parser = argparse.ArgumentParser(description="Download and convert finf/fsr-protocols using pandoc")
parser.add_argument("-urls", nargs="+", type=str, default=[])
......@@ -515,3 +513,7 @@ if __name__ == '__main__':
if parsed.compile:
pads.compile_pads()
if __name__ == '__main__':
main()
......@@ -6,7 +6,7 @@ import linkToPDF2 as pter
import pterClasses
class ProtokollGUI(tk.Tk):
class ProtocolGUI(tk.Tk):
def __init__(self, opt: config.Config):
super().__init__(screenName="ProtokollHelper")
self.opt = opt
......@@ -34,16 +34,16 @@ class ProtokollGUI(tk.Tk):
def update_folder_index(self, i):
@wraps(self.update_folder_index)
def wrapper(*args, **kwargs):
def wrapper(*_, **__):
self.folder_index = (self.folder_index + i) % len(self.folders)
self.update_pad_frame()
return wrapper
def update_pad_frame(self):
folderName = list(self.folders.keys())[self.folder_index]
self.folder_label.configure(text=folderName)
self.current_pads = [p for p in self.folders[folderName] if isinstance(p, pter.ProtocolPad)]
folder_name = list(self.folders.keys())[self.folder_index]
self.folder_label.configure(text=folder_name)
self.current_pads = [p for p in self.folders[folder_name] if isinstance(p, pter.ProtocolPad)]
for i, pad in enumerate(self.current_pads):
assert isinstance(pad, pter.ProtocolPad)
approved_state = tk.NORMAL if pad.is_approved else tk.DISABLED
......@@ -57,7 +57,7 @@ class ProtokollGUI(tk.Tk):
# Button Compile
btn_compile = tk.Button(self.pad_frame, text="Compile",
command=pad.compile)
command=pad.compile_)
btn_compile.grid(row=i, column=3)
# Button Mail FR
......@@ -67,7 +67,7 @@ class ProtokollGUI(tk.Tk):
# Button Mail FR-Info
btn_mail_fr_info = tk.Button(self.pad_frame, text="FR-Info Mail", state=approved_state, bg=color,
command=pad.send_mail_as_approved)
command=pad.send_mail_as_approved)
btn_mail_fr_info.grid(row=i, column=5)
# Button Website
......@@ -83,5 +83,5 @@ class ProtokollGUI(tk.Tk):
if __name__ == '__main__':
pter.opt.GREMIUM = pterClasses.GREMIUM_FR
gui = ProtokollGUI(pter.opt)
gui = ProtocolGUI(pter.opt)
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