Commit 18082c41 authored by dwoiwode's avatar dwoiwode
Browse files

Merge remote-tracking branch 'origin/pter2.0' into pter2.0

# Conflicts:
#	linkToPDF2.py
#	pterClasses.py
parents 8943dba6 b7678739
......@@ -22,8 +22,7 @@ class Semester:
def __post_init__(self):
self.display_name = f"{self.part.value} {self.year}"
self.grav_path = os.path.join(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()}"
......@@ -41,12 +40,12 @@ class Semester:
return Semester(date.year - 1, SemesterPart.Winter)
def upload_to_grav(self):
if os.path.exists(self.grav_path):
if self.grav_path.exists():
return
git = opt.git
os.makedirs(str(Path(self.grav_path).parent), exist_ok=True)
with open(self.grav_path, "w") as d:
self.grav_path.parent.mkdir(parents=True, exist_ok=True)
with self.grav_path.open("w") as d:
d.write(f"---\ntitle: {self.display_name}\n---")
git.add(opt.GRAV_PROTOCOL_PATH)
......@@ -151,25 +150,25 @@ class BasePad:
return self.source.url
@property
def raw_path(self) -> Path:
return Path(os.path.join(opt.DATA_FOLDER, "raw", f"{self.display_name}.md")).absolute()
def rawPath(self) -> Path:
return Path(opt.DATA_FOLDER).absolute() / "raw" / f"{self.display_name}.md"
@property
def compiled_path(self) -> Path:
return Path(os.path.join(opt.DATA_FOLDER, "result", f"{self.display_name}.pdf")).absolute()
def compiledPath(self) -> Path:
return Path(opt.DATA_FOLDER).absolute() / "result" / f"{self.display_name}.pdf"
def download(self, override=True):
path = self.raw_path
content = self.source.retrieve_content()
if not override and os.path.exists(str(path)):
raise FileExistsError(f"{path} already exists!")
os.makedirs(str(path.parent), exist_ok=True)
with open(str(path), "w", encoding="utf-8") as d:
content = self.source.retrieveContent()
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)
with self.raw_path.open("w", encoding="utf-8") as d:
d.write(content)
self.source = LocalCache(self.source.url, str(path))
self.source = LocalCache(self.source.url, str(self.raw_path))
def compile(self, template: str = None) -> int:
os.makedirs(str(self.compiled_path.parent), exist_ok=True)
def compile(self, template: str = None) -> int:
self.compiledPath.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()
......@@ -204,10 +203,9 @@ class ProtocolPad(BasePad):
@property
def grav_path(self) -> Path:
return Path(os.path.join(opt.GIT_REPO_PATH, opt.GRAV_PROTOCOL_PATH,
self.semester._grav_name(),
self.date.strftime("%Y-%m-%d") + "-fgvv" * self.is_fachgruppenvollversammlung,
"default.de.md")).absolute()
return Path(
opt.GIT_REPO_PATH).absolute() / opt.GRAV_PROTOCOL_PATH / self.semester._grav_name() / self.date.strftime(
"%Y-%m-%d") / str("-fgvv" * self.is_fachgruppenvollversammlung) / "default.de.md"
def parse_tops(self):
# TODO: better top filter?
......@@ -289,7 +287,7 @@ class ProtocolPad(BasePad):
# Init semester
# TODO: better file management
self.semester.upload_to_grav()
if not os.path.exists(str(self.raw_path)):
if not self.raw_path.exists():
raise FileNotFoundError(f"{self.raw_path} doesn't exist")
# TODO: move conversion to another method?
......@@ -309,8 +307,8 @@ class ProtocolPad(BasePad):
"---\n\n"
"[MINITOC]\n\n")
# Upload
os.makedirs(str(self.grav_path.parent), exist_ok=True)
with open(str(self.grav_path), "w", encoding="utf-8") as f:
self.grav_path.parent.mkdir(parents=True, exist_ok=True)
with self.grav_path.open("w", encoding="utf-8") as f:
f.write(header + self.cleaned_raw())
git = opt.git
......
......@@ -19,7 +19,7 @@ class Gremium:
def full_template(self):
from linkToPDF2 import opt
return str(Path(os.path.join(opt.TEMPLATE_FOLDER, self.template)).absolute())
return Path(opt.TEMPLATE_FOLDER).absolute() / self.template
GREMIUM_FR = Gremium("finf", "Fachrat Informatik", "pandoc.finf.tex")
......@@ -62,7 +62,7 @@ def send_fr_mail(text: str, subject: str, sender: MailParticipant, receivers: Li
mail.attach(msg)
if attachment is not None:
payload = MIMEBase('application', 'octet-stream')
with open(str(attachment.compiled_path), "rb") as d:
with attachment.compiled_path.open("rb") as d:
payload.set_payload(d.read())
encoders.encode_base64(payload)
payload.add_header('Content-Disposition',
......
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