From 3ce93a17eb32eb11fa53c722c6ea4cbbd1ac99e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Thu, 16 Sep 2021 18:18:51 +0200 Subject: [PATCH] check if courseignore file is present first. handle directories without an info file and produce warning in this case --- scripts/courses.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/scripts/courses.py b/scripts/courses.py index 95c9ee9..d47431c 100755 --- a/scripts/courses.py +++ b/scripts/courses.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 from pathlib import Path import yaml +import warnings from lectures import Lectures from notes import Notes @@ -12,8 +13,13 @@ class Course: def __init__(self, path): self.path = path self.name = path.stem - - self.info = yaml.safe_load((path / COURSE_INFO_FILE).open()) + if (path / COURSE_INFO_FILE).is_file(): + self.info = yaml.safe_load((path / COURSE_INFO_FILE).open()) + else: + warnings.warn(f"No course info file found in directory '{path.stem}'. Place a {COURSE_INFO_FILE} " + f"file in the directory or add the directory to the course ignore file named" + f" '{COURSE_IGNORE_FILE}' in your root directory ({ROOT})") + self.info = {'title': path.stem, 'short': path.stem} self._notes = None @property @@ -29,12 +35,14 @@ class Course: def ignored_courses(): - with open(ROOT / COURSE_IGNORE_FILE) as ignore: - lines = ignore.readlines() - paths = [] - for line in lines: - paths.append(ROOT / line.strip()) - return paths + if (ROOT / COURSE_IGNORE_FILE).is_file(): + with open(ROOT / COURSE_IGNORE_FILE) as ignore: + lines = ignore.readlines() + paths = [] + for line in lines: + paths.append(ROOT / line.strip()) + return paths + return [] def read_files():