2019-09-15 20:42:11 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
from pathlib import Path
|
|
|
|
import yaml
|
|
|
|
|
|
|
|
from lectures import Lectures
|
2021-09-16 12:35:25 +02:00
|
|
|
from config import ROOT, CURRENT_COURSE_ROOT, CURRENT_COURSE_SYMLINK, CURRENT_COURSE_WATCH_FILE, COURSE_IGNORE_FILE, COURSE_INFO_FILE
|
2019-09-15 20:42:11 +02:00
|
|
|
class Course():
|
|
|
|
def __init__(self, path):
|
|
|
|
self.path = path
|
|
|
|
self.name = path.stem
|
|
|
|
|
2021-09-16 12:35:25 +02:00
|
|
|
self.info = yaml.load((path / COURSE_INFO_FILE).open())
|
2019-09-15 20:42:11 +02:00
|
|
|
self._lectures = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def lectures(self):
|
|
|
|
if not self._lectures:
|
|
|
|
self._lectures = Lectures(self)
|
|
|
|
return self._lectures
|
|
|
|
|
|
|
|
def __eq__(self, other):
|
|
|
|
if other == None:
|
|
|
|
return False
|
|
|
|
return self.path == other.path
|
|
|
|
|
|
|
|
class Courses(list):
|
|
|
|
def __init__(self):
|
|
|
|
list.__init__(self, self.read_files())
|
|
|
|
|
|
|
|
def read_files(self):
|
2021-09-16 12:26:17 +02:00
|
|
|
course_directories = [x for x in ROOT.iterdir() if x.is_dir() and not x in self.ignored_courses()]
|
2019-09-15 20:42:11 +02:00
|
|
|
_courses = [Course(path) for path in course_directories]
|
|
|
|
return sorted(_courses, key=lambda c: c.name)
|
|
|
|
|
2021-09-16 12:26:17 +02:00
|
|
|
def ignored_courses(self):
|
2021-09-16 12:34:32 +02:00
|
|
|
with open(ROOT / COURSE_IGNORE_FILE) as ignore:
|
2021-09-16 12:26:17 +02:00
|
|
|
lines = ignore.readlines()
|
|
|
|
paths = []
|
|
|
|
for line in lines:
|
|
|
|
paths.append(ROOT / line.strip())
|
|
|
|
return paths
|
|
|
|
|
2019-09-15 20:42:11 +02:00
|
|
|
@property
|
|
|
|
def current(self):
|
|
|
|
return Course(CURRENT_COURSE_ROOT.resolve())
|
|
|
|
|
|
|
|
@current.setter
|
|
|
|
def current(self, course):
|
|
|
|
CURRENT_COURSE_SYMLINK.unlink()
|
|
|
|
CURRENT_COURSE_SYMLINK.symlink_to(course.path)
|
|
|
|
CURRENT_COURSE_WATCH_FILE.write_text('{}\n'.format(course.info['short']))
|