add Links class to courses to manage course links

This commit is contained in:
Maximilian Keßler 2021-09-17 12:42:08 +02:00
parent 2f646b0780
commit 9b528a91a2
2 changed files with 26 additions and 0 deletions

View File

@ -7,6 +7,7 @@ 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
from notes import Notes from notes import Notes
from links import Links
from utils import merge_dictionaries from utils import merge_dictionaries
@ -30,6 +31,13 @@ class Course:
fallback_file = {} fallback_file = {}
self.info = merge_dictionaries(self.info, fallback_file) self.info = merge_dictionaries(self.info, fallback_file)
self._notes = None self._notes = None
self._links = None
@property
def links(self) -> Links:
if not self._links:
self._links = Links(self)
return self._links
@property @property
def notes(self) -> Notes: def notes(self) -> Notes:

18
scripts/links.py Normal file
View File

@ -0,0 +1,18 @@
import subprocess
class Links:
def __init__(self, course):
self.course = course # A course
self.info = course.info['links']
def open(self, key: str):
self.open_link_in_browser(self.info[key])
@staticmethod
def open_link_in_browser(url):
result = subprocess.run(
['qutebrowser', str(url)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL
)