add edit file for central place of edit method. add methods to edit master file or full file

This commit is contained in:
Maximilian Keßler 2021-09-17 09:43:54 +02:00
parent 9f498a7c61
commit 12b1632f8e
5 changed files with 45 additions and 15 deletions

View file

@ -1,10 +0,0 @@
#!/bin/python3
from courses import Courses
for course in Courses():
script = course.notes
lectures = script.lectures
r = lectures.parse_range_string('all')
script.update_lectures_in_master(r)
script.compile_master()

View file

@ -0,0 +1,13 @@
#!/bin/python3
from courses import Courses
for course in Courses():
notes = course.notes
if notes.full_file:
notes.compile_full()
continue
else:
lectures = notes.lectures
r = lectures.parse_range_string('all')
notes.update_lectures_in_master(r)
notes.compile_master()

12
scripts/edit.py Normal file
View file

@ -0,0 +1,12 @@
#! /usr/bin/python3
import subprocess
from pathlib import Path
def edit(filepath: Path):
subprocess.Popen([
"termite",
"-e",
f"vim --servername tex-vorlesung --remote-silent {str(filepath)}"
])

View file

@ -7,6 +7,7 @@ from datetime import datetime
from config import DATE_FORMAT, LOCALE, DEFAULT_NEW_LECTURE_HEADER, DEFAULT_LECTURE_SEARCH_REGEX
from utils import get_week
from edit import edit
# TODO
locale.setlocale(locale.LC_TIME, LOCALE)
@ -44,11 +45,7 @@ class Lecture:
self.course = course
def edit(self):
subprocess.Popen([
"x-terminal-emulator",
"-e", "zsh", "-i", "-c",
f"\\vim --servername kulak --remote-silent {str(self.file_path)}"
])
edit(self.file_path)
def __str__(self):
return f'<Lecture {self.course.info["short"]} {self.number} "{self.title}">'

View file

@ -5,6 +5,7 @@ from pathlib import Path
from lectures import Lectures, number2filename
from config import DEFAULT_MASTER_FILE_NAME, LECTURE_START_MARKER, LECTURE_END_MARKER, DEFAULT_IMPORT_INDENTATION
from parse_counters import parse_counters, dict2setcounters
from edit import edit
class Notes:
@ -85,6 +86,12 @@ class Notes:
if self.full_file:
self.update_lectures_in_file(self.full_file, lecture_list)
def edit_master(self):
edit(self.master_file)
def edit_full(self):
edit(self.full_file)
def compile_master(self):
result = subprocess.run(
['latexmk', '-f', '-interaction=nonstopmode', str(self.master_file)],
@ -94,6 +101,17 @@ class Notes:
)
return result.returncode
def compile_full(self):
if not self.full_file:
return 0
result = subprocess.run(
['latexmk', '-f', '-interaction=nonstopmode', str(self.full_file)],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
cwd=str(self.root)
)
return result.returncode
@property
def lectures(self):
if not self._lectures: