check if courseignore file is present first. handle directories without an info file and produce warning in this case
This commit is contained in:
parent
51b5c5dd00
commit
3ce93a17eb
1 changed files with 16 additions and 8 deletions
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import yaml
|
import yaml
|
||||||
|
import warnings
|
||||||
|
|
||||||
from lectures import Lectures
|
from lectures import Lectures
|
||||||
from notes import Notes
|
from notes import Notes
|
||||||
|
@ -12,8 +13,13 @@ class Course:
|
||||||
def __init__(self, path):
|
def __init__(self, path):
|
||||||
self.path = path
|
self.path = path
|
||||||
self.name = path.stem
|
self.name = path.stem
|
||||||
|
if (path / COURSE_INFO_FILE).is_file():
|
||||||
self.info = yaml.safe_load((path / COURSE_INFO_FILE).open())
|
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
|
self._notes = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -29,12 +35,14 @@ class Course:
|
||||||
|
|
||||||
|
|
||||||
def ignored_courses():
|
def ignored_courses():
|
||||||
with open(ROOT / COURSE_IGNORE_FILE) as ignore:
|
if (ROOT / COURSE_IGNORE_FILE).is_file():
|
||||||
lines = ignore.readlines()
|
with open(ROOT / COURSE_IGNORE_FILE) as ignore:
|
||||||
paths = []
|
lines = ignore.readlines()
|
||||||
for line in lines:
|
paths = []
|
||||||
paths.append(ROOT / line.strip())
|
for line in lines:
|
||||||
return paths
|
paths.append(ROOT / line.strip())
|
||||||
|
return paths
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
def read_files():
|
def read_files():
|
||||||
|
|
Loading…
Reference in a new issue