refactor files
This commit is contained in:
parent
6fe7fc4938
commit
b8c2f236a4
2 changed files with 33 additions and 29 deletions
|
@ -3,8 +3,11 @@ from pathlib import Path
|
|||
import yaml
|
||||
|
||||
from lectures import Lectures
|
||||
from config import ROOT, CURRENT_COURSE_ROOT, CURRENT_COURSE_SYMLINK, CURRENT_COURSE_WATCH_FILE, COURSE_IGNORE_FILE, COURSE_INFO_FILE
|
||||
class Course():
|
||||
from config import ROOT, CURRENT_COURSE_ROOT, CURRENT_COURSE_SYMLINK, CURRENT_COURSE_WATCH_FILE, COURSE_IGNORE_FILE, \
|
||||
COURSE_INFO_FILE
|
||||
|
||||
|
||||
class Course:
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
self.name = path.stem
|
||||
|
@ -19,20 +22,12 @@ class Course():
|
|||
return self._lectures
|
||||
|
||||
def __eq__(self, other):
|
||||
if other == None:
|
||||
if other is None:
|
||||
return False
|
||||
return self.path == other.path
|
||||
|
||||
class Courses(list):
|
||||
def __init__(self):
|
||||
list.__init__(self, self.read_files())
|
||||
|
||||
def read_files(self):
|
||||
course_directories = [x for x in ROOT.iterdir() if x.is_dir() and not x in self.ignored_courses()]
|
||||
_courses = [Course(path) for path in course_directories]
|
||||
return sorted(_courses, key=lambda c: c.name)
|
||||
|
||||
def ignored_courses(self):
|
||||
def ignored_courses():
|
||||
with open(ROOT / COURSE_IGNORE_FILE) as ignore:
|
||||
lines = ignore.readlines()
|
||||
paths = []
|
||||
|
@ -40,6 +35,17 @@ class Courses(list):
|
|||
paths.append(ROOT / line.strip())
|
||||
return paths
|
||||
|
||||
|
||||
def read_files():
|
||||
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]
|
||||
return sorted(_courses, key=lambda c: c.name)
|
||||
|
||||
|
||||
class Courses(list):
|
||||
def __init__(self):
|
||||
list.__init__(self, read_files())
|
||||
|
||||
@property
|
||||
def current(self):
|
||||
return Course(CURRENT_COURSE_ROOT.resolve())
|
||||
|
|
|
@ -1,14 +1,11 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
import locale
|
||||
import re
|
||||
import subprocess
|
||||
from datetime import datetime
|
||||
|
||||
|
||||
from config import get_week, DATE_FORMAT, CURRENT_COURSE_ROOT, LOCALE, DEFAULT_MASTER_FILE_NAME
|
||||
from config import get_week, DATE_FORMAT, LOCALE, DEFAULT_MASTER_FILE_NAME
|
||||
|
||||
# TODO
|
||||
locale.setlocale(locale.LC_TIME, LOCALE)
|
||||
|
@ -17,16 +14,18 @@ locale.setlocale(locale.LC_TIME, LOCALE)
|
|||
def number2filename(n):
|
||||
return 'lec_{0:02d}.tex'.format(n)
|
||||
|
||||
|
||||
def filename2number(s):
|
||||
return int(str(s).replace('.tex', '').replace('lec_', ''))
|
||||
|
||||
class Lecture():
|
||||
|
||||
class Lecture:
|
||||
def __init__(self, file_path, course):
|
||||
with file_path.open() as f:
|
||||
for line in f:
|
||||
lecture_match = re.search(r'lecture\{(.*?)\}\{(.*?)\}\{(.*)\}', line)
|
||||
lecture_match = re.search(r'lecture{(.*?)}{(.*?)}{(.*)}', line)
|
||||
if lecture_match:
|
||||
break;
|
||||
break
|
||||
|
||||
# number = int(lecture_match.group(1))
|
||||
|
||||
|
@ -108,7 +107,7 @@ class Lectures(list):
|
|||
|
||||
if 'start lectures' in line:
|
||||
part = 1
|
||||
return (header, footer)
|
||||
return header, footer
|
||||
|
||||
def update_lectures_in_master(self, r):
|
||||
header, footer = self.get_header_footer(self.master_file)
|
||||
|
@ -137,10 +136,9 @@ class Lectures(list):
|
|||
|
||||
self.read_files()
|
||||
|
||||
lec = Lecture(new_lecture_path, self.course)
|
||||
|
||||
l = Lecture(new_lecture_path, self.course)
|
||||
|
||||
return l
|
||||
return lec
|
||||
|
||||
def compile_master(self):
|
||||
result = subprocess.run(
|
||||
|
|
Loading…
Reference in a new issue