Commit a872c887 authored by dwoiwode's avatar dwoiwode
Browse files

Style cleanup #1

parent 90827451
import datetime
import hashlib
import os
import subprocess
from dataclasses import dataclass
from pathlib import Path
from typing import Optional, Dict, List, Iterator, Tuple
......@@ -51,6 +53,10 @@ class Semester:
git.commit(f"Added {self.part.value} {self.year}")
git.push()
def uploadToCloud(self):
# TODO: Upload semester folder to cloud if not exists
pass
# === Source Types ===
class SourceTypes:
......@@ -68,7 +74,7 @@ class Etherpad(SourceTypes):
def retrieveContent(self):
url = f"{self.url}.txt"
response = requests.get(url)
return response.content.decode("utf-8")
return response.text
@classmethod
def fitUrl(cls, url: str) -> bool:
......@@ -80,7 +86,7 @@ class CodiMD(SourceTypes):
def retrieveContent(self):
url = f"{self.url}/download"
response = requests.get(url)
return response.content.decode("utf-8")
return response.text
@classmethod
def fitUrl(cls, url: str) -> bool:
......@@ -164,15 +170,18 @@ class BasePad:
def compile(self, template: str = None) -> int:
os.makedirs(str(self.compiledPath.parent), exist_ok=True)
metadataStr = (" " +
" ".join([f'-M {key}="{val}"' for key, val in self.metadata.items()]))
templateStr = ""
metadata = [f'-M {key}="{val}"' for key, val in self.metadata.items()]
if template is None and hasattr(self, "gremium"):
templateStr = f' --template="{getattr(self, "gremium").fullTemplate()}" '
elif template != "":
templateStr = f' --template="{template}" '
cmd = f'pandoc "{self.rawPath}" {metadataStr}{templateStr}-o "{str(self.compiledPath)}"'
ret = os.system(cmd)
template = getattr(self, "gremium").fullTemplate()
proc = subprocess.run([
"pandoc",
f"{self.rawPath}",
*metadata,
f"--template={template}",
"-o",
f"{self.compiledPath}"
])
ret = proc.returncode
if ret != 0:
raise RuntimeWarning(f"Non-Zero Returncode ({ret})")
return ret
......@@ -271,7 +280,10 @@ class ProtocolPad(BasePad):
return True
def uploadToCloud(self):
pass
assert isinstance(self.semester, Semester)
self.semester.uploadToCloud()
# TODO: Upload pdf to cloud in semester-folder
# TODO: Upload raw md to cloud
def uploadToGrav(self):
# Init semester
......
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