add some more type hints. add methods to open master or full pdf file
This commit is contained in:
parent
c1e2fe5500
commit
2f646b0780
2 changed files with 25 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
||||||
import warnings
|
import warnings
|
||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
from typing import List
|
||||||
|
|
||||||
from config import ROOT, CURRENT_COURSE_ROOT, CURRENT_COURSE_SYMLINK, CURRENT_COURSE_WATCH_FILE, COURSE_IGNORE_FILE, \
|
from config import ROOT, CURRENT_COURSE_ROOT, CURRENT_COURSE_SYMLINK, CURRENT_COURSE_WATCH_FILE, COURSE_IGNORE_FILE, \
|
||||||
COURSE_INFO_FILE_NAME, FALLBACK_COURSE_INFO_FILE
|
COURSE_INFO_FILE_NAME, FALLBACK_COURSE_INFO_FILE
|
||||||
|
@ -31,7 +32,7 @@ class Course:
|
||||||
self._notes = None
|
self._notes = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def notes(self):
|
def notes(self) -> Notes:
|
||||||
if not self._notes:
|
if not self._notes:
|
||||||
self._notes = Notes(self)
|
self._notes = Notes(self)
|
||||||
return self._notes
|
return self._notes
|
||||||
|
@ -42,7 +43,7 @@ class Course:
|
||||||
return self.path == other.path
|
return self.path == other.path
|
||||||
|
|
||||||
|
|
||||||
def ignored_courses():
|
def ignored_courses() -> List[Course]:
|
||||||
if (ROOT / COURSE_IGNORE_FILE).is_file():
|
if (ROOT / COURSE_IGNORE_FILE).is_file():
|
||||||
with open(ROOT / COURSE_IGNORE_FILE) as ignore:
|
with open(ROOT / COURSE_IGNORE_FILE) as ignore:
|
||||||
lines = ignore.readlines()
|
lines = ignore.readlines()
|
||||||
|
@ -53,7 +54,7 @@ def ignored_courses():
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
|
||||||
def read_files():
|
def read_files() -> List[Course]:
|
||||||
course_directories = [x for x in ROOT.iterdir() if x.is_dir() and x not in ignored_courses()]
|
course_directories = [x for x in ROOT.iterdir() if x.is_dir() and x not in ignored_courses()]
|
||||||
_courses = [Course(path) for path in course_directories]
|
_courses = [Course(path) for path in course_directories]
|
||||||
return sorted(_courses, key=lambda c: c.name)
|
return sorted(_courses, key=lambda c: c.name)
|
||||||
|
@ -64,7 +65,7 @@ class Courses(list):
|
||||||
list.__init__(self, read_files())
|
list.__init__(self, read_files())
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def current(self):
|
def current(self) -> Course:
|
||||||
return Course(CURRENT_COURSE_ROOT.resolve())
|
return Course(CURRENT_COURSE_ROOT.resolve())
|
||||||
|
|
||||||
@current.setter
|
@current.setter
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
import subprocess
|
import subprocess
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from typing import Dict
|
||||||
|
|
||||||
from config import LECTURE_START_MARKER, LECTURE_END_MARKER, DEFAULT_IMPORT_INDENTATION
|
from config import LECTURE_START_MARKER, LECTURE_END_MARKER, DEFAULT_IMPORT_INDENTATION
|
||||||
from edit import edit
|
from edit import edit
|
||||||
|
@ -10,12 +11,12 @@ from parse_counters import parse_counters, dict2setcounters
|
||||||
|
|
||||||
class Notes:
|
class Notes:
|
||||||
def __init__(self, course):
|
def __init__(self, course):
|
||||||
self.course = course
|
self.course = course # A course
|
||||||
self.info = course.info['notes']
|
self.info: Dict = course.info['notes']
|
||||||
self.root = course.path / self.info['path']
|
self.root: Path = course.path / self.info['path']
|
||||||
self.root.mkdir(parents=True, exist_ok=True)
|
self.root.mkdir(parents=True, exist_ok=True)
|
||||||
self.master_file = self.root / self.info['master_file']
|
self.master_file: Path = self.root / self.info['master_file']
|
||||||
self.full_file = self.root / self.info['full_file']
|
self.full_file: Path = self.root / self.info['full_file']
|
||||||
self._lectures = None
|
self._lectures = None
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -80,6 +81,20 @@ class Notes:
|
||||||
def edit_full(self):
|
def edit_full(self):
|
||||||
edit(self.full_file)
|
edit(self.full_file)
|
||||||
|
|
||||||
|
def open_master(self):
|
||||||
|
result = subprocess.run(
|
||||||
|
['zathura', str(self.master_file.with_suffix('.pdf'))],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
|
||||||
|
def open_full(self):
|
||||||
|
result = subprocess.run(
|
||||||
|
['zathura', str(self.full_file.with_suffix('.pdf'))],
|
||||||
|
stdout=subprocess.DEVNULL,
|
||||||
|
stderr=subprocess.DEVNULL
|
||||||
|
)
|
||||||
|
|
||||||
def compile_master(self):
|
def compile_master(self):
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
['latexmk', '-f', '-interaction=nonstopmode', str(self.master_file)],
|
['latexmk', '-f', '-interaction=nonstopmode', str(self.master_file)],
|
||||||
|
|
Loading…
Reference in a new issue