From 12b1632f8ed65f6d67200aa399f93172b7f43411 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maximilian=20Ke=C3=9Fler?= Date: Fri, 17 Sep 2021 09:43:54 +0200 Subject: [PATCH] add edit file for central place of edit method. add methods to edit master file or full file --- scripts/compile-all-masters.py | 10 ---------- scripts/compile_all_full_versions.py | 13 +++++++++++++ scripts/edit.py | 12 ++++++++++++ scripts/lectures.py | 7 ++----- scripts/notes.py | 18 ++++++++++++++++++ 5 files changed, 45 insertions(+), 15 deletions(-) delete mode 100755 scripts/compile-all-masters.py create mode 100755 scripts/compile_all_full_versions.py create mode 100644 scripts/edit.py diff --git a/scripts/compile-all-masters.py b/scripts/compile-all-masters.py deleted file mode 100755 index 96df6a9..0000000 --- a/scripts/compile-all-masters.py +++ /dev/null @@ -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() diff --git a/scripts/compile_all_full_versions.py b/scripts/compile_all_full_versions.py new file mode 100755 index 0000000..a0d4659 --- /dev/null +++ b/scripts/compile_all_full_versions.py @@ -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() diff --git a/scripts/edit.py b/scripts/edit.py new file mode 100644 index 0000000..dfb708d --- /dev/null +++ b/scripts/edit.py @@ -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)}" + ]) diff --git a/scripts/lectures.py b/scripts/lectures.py index eb73861..a91556e 100644 --- a/scripts/lectures.py +++ b/scripts/lectures.py @@ -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'' diff --git a/scripts/notes.py b/scripts/notes.py index a55e257..ca6983e 100644 --- a/scripts/notes.py +++ b/scripts/notes.py @@ -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: