add Links class to courses to manage course links
This commit is contained in:
parent
2f646b0780
commit
9b528a91a2
2 changed files with 26 additions and 0 deletions
|
@ -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, \
|
||||
COURSE_INFO_FILE_NAME, FALLBACK_COURSE_INFO_FILE
|
||||
from notes import Notes
|
||||
from links import Links
|
||||
from utils import merge_dictionaries
|
||||
|
||||
|
||||
|
@ -30,6 +31,13 @@ class Course:
|
|||
fallback_file = {}
|
||||
self.info = merge_dictionaries(self.info, fallback_file)
|
||||
self._notes = None
|
||||
self._links = None
|
||||
|
||||
@property
|
||||
def links(self) -> Links:
|
||||
if not self._links:
|
||||
self._links = Links(self)
|
||||
return self._links
|
||||
|
||||
@property
|
||||
def notes(self) -> Notes:
|
||||
|
|
18
scripts/links.py
Normal file
18
scripts/links.py
Normal 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
|
||||
)
|
Loading…
Reference in a new issue