add method for making a new exercise sheet write up
This commit is contained in:
parent
8659206ee6
commit
b2fded51e6
4 changed files with 56 additions and 6 deletions
|
@ -26,3 +26,23 @@ FALLBACK_COURSE_INFO_FILE = Path(__file__).parent.resolve() / 'fallback.yaml'
|
|||
TIMEZONE = pytz.timezone('CET')
|
||||
SCHEDULER_DELAY = 60
|
||||
DEFAULT_LATEX_COUNTER_AUX_FILE_EXTENSION = '.cnt'
|
||||
|
||||
NEW_EXERCISE_SHEET_HEADER = '\n'.join([
|
||||
r"%! TEX root = ./*.tex",
|
||||
r"\documentclass[{language}]{{mkessler-sheet}}",
|
||||
"",
|
||||
r"\usepackage{{babel}}",
|
||||
r"\usepackage{{mkessler-math}}",
|
||||
r"\usepackage{{mkessler-enumerate}}",
|
||||
r"\usepackage{{mkessler-figures}}",
|
||||
"",
|
||||
r"\author{{{author}}}",
|
||||
r"\course{{{course}}}",
|
||||
r"\sheetnumber{{{number}}}",
|
||||
"",
|
||||
r"\begin{{document}}",
|
||||
r"\maketitle",
|
||||
"",
|
||||
"",
|
||||
r"\end{{document}}"
|
||||
])
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
from file_list import Files, FileHandle, FileType
|
||||
from pathlib import Path
|
||||
from typing import Dict
|
||||
from utils import normalize
|
||||
from config import NEW_EXERCISE_SHEET_HEADER
|
||||
|
||||
|
||||
class ExerciseWriteUp(FileHandle):
|
||||
|
@ -70,6 +72,30 @@ class Exercises(list):
|
|||
self._writeups = sorted((ExerciseWriteUp(d, self.course) for d in dirs), key=lambda e: e.number)
|
||||
return self._writeups
|
||||
|
||||
def read_write_up_dirs(self):
|
||||
dirs = self.root.iterdir()
|
||||
return sorted((ExerciseWriteUp(d, self.course) for d in dirs if d is not self.sheets), key=lambda e: e.number)
|
||||
@staticmethod
|
||||
def __generate_name(name: str):
|
||||
return normalize(name.split(' ')[-1])
|
||||
|
||||
def __generate_names(self):
|
||||
names = self.info['name']
|
||||
if type(names) == str:
|
||||
return self.__generate_name(names)
|
||||
elif type(names) == list:
|
||||
return '_'.join(map(self.__generate_name, names))
|
||||
|
||||
def new_writeup(self):
|
||||
new_num = max(self.writeups, key=lambda w: w.number).number + 1
|
||||
new_dir = self.root / 'ub{num}'.format(num=new_num)
|
||||
new_dir.mkdir(parents=True, exist_ok=False)
|
||||
new_file = new_dir / '{names}_{course}_sheet_{num}.tex'.format(
|
||||
names=self.__generate_names(),
|
||||
course=normalize(self.course.info['short']),
|
||||
num=new_num
|
||||
)
|
||||
new_file.write_text(NEW_EXERCISE_SHEET_HEADER.format(
|
||||
language='ngerman' if self.course.info['language'] == 'german' else 'english',
|
||||
author=self.info['name'] if type(self.info['name']) == str else ', '.join(self.info['name']),
|
||||
course=self.course.info['title'],
|
||||
number=new_num
|
||||
))
|
||||
ExerciseWriteUp(new_dir, self.course).open()
|
||||
|
|
|
@ -37,13 +37,13 @@ def rofi_pick_exercise(spec: str = 'writeup'):
|
|||
|
||||
if key == 0:
|
||||
sorted_ex[index].open()
|
||||
elif key == 1:
|
||||
pass # TODO: make new exercise
|
||||
elif key == 1 and spec == 'writeup':
|
||||
exercises.new_writeup()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if not len(sys.argv) == 1:
|
||||
print('Please specify exactly one of "writeup", "solution" and "sheet"')
|
||||
exit(1)
|
||||
rofi_pick_exercise('sheet')
|
||||
rofi_pick_exercise('writeup')
|
||||
exit(0)
|
||||
|
|
|
@ -13,6 +13,10 @@ def unbeautify(string):
|
|||
return string.replace(' ', '-').lower()
|
||||
|
||||
|
||||
def normalize(string):
|
||||
return string.lower().replace('ä', 'ae').replace('ö', 'oe').replace('ü', 'ue').replace('ß', 'ss')
|
||||
|
||||
|
||||
def generate_short_title(title):
|
||||
short_title = title or 'Untitled'
|
||||
if len(title) >= MAX_LEN:
|
||||
|
|
Loading…
Reference in a new issue