[UPDATE] интеграция: безопасные маунты, кэш в tmpdir, только .tex/.pdf
This commit is contained in:
+33
-17
@@ -1,6 +1,8 @@
|
||||
import argparse
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
from md2gost.parser import Parser
|
||||
@@ -44,27 +46,41 @@ def main():
|
||||
renderer = Renderer(parser.tokens, parser.front_matter)
|
||||
latex = renderer.render()
|
||||
|
||||
tex_path = args.output / args.input.with_suffix(".tex").name
|
||||
tex_path.write_text(latex, encoding="utf-8")
|
||||
print(f"→ {tex_path}")
|
||||
# Собираем во временную директорию, копируем только .tex и .pdf
|
||||
with tempfile.TemporaryDirectory(prefix="md2gost-") as cache:
|
||||
cache_dir = Path(cache)
|
||||
|
||||
if not args.no_pdf:
|
||||
pdf_path = args.output / args.input.with_suffix(".pdf").name
|
||||
log_path = args.output / "report.log"
|
||||
# Генерируем .tex в кэш
|
||||
tex_name = args.input.with_suffix(".tex").name
|
||||
tex_path = cache_dir / tex_name
|
||||
tex_path.write_text(latex, encoding="utf-8")
|
||||
|
||||
if not run_xelatex(tex_path, args.output):
|
||||
print("ошибка: xelatex не собрал PDF", file=sys.stderr)
|
||||
if log_path.exists():
|
||||
for line in log_path.read_text(errors="replace").splitlines():
|
||||
if line.startswith("!"):
|
||||
print(f" {line}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
# Копируем .tex в выходную директорию
|
||||
final_tex = args.output / tex_name
|
||||
shutil.copy2(tex_path, final_tex)
|
||||
print(f"→ {final_tex}")
|
||||
|
||||
if not run_xelatex(tex_path, args.output):
|
||||
print("ошибка: xelatex (2-й проход) не собрал PDF", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
if not args.no_pdf:
|
||||
# Компилируем PDF в кэше (два прохода для TOC)
|
||||
if not run_xelatex(tex_path, cache_dir):
|
||||
print("ошибка: xelatex не собрал PDF", file=sys.stderr)
|
||||
log_path = cache_dir / "report.log"
|
||||
if log_path.exists():
|
||||
for line in log_path.read_text(errors="replace").splitlines():
|
||||
if line.startswith("!"):
|
||||
print(f" {line}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
print(f"→ {pdf_path}")
|
||||
if not run_xelatex(tex_path, cache_dir):
|
||||
print("ошибка: xelatex (2-й проход) не собрал PDF", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
# Копируем .pdf в выходную директорию
|
||||
pdf_name = args.input.with_suffix(".pdf").name
|
||||
pdf_path = cache_dir / pdf_name
|
||||
final_pdf = args.output / pdf_name
|
||||
shutil.copy2(pdf_path, final_pdf)
|
||||
print(f"→ {final_pdf}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user