36 lines
933 B
Python
Executable file
36 lines
933 B
Python
Executable file
#!/usr/bin/env python
|
|
import subprocess
|
|
from pathlib import Path
|
|
import sys
|
|
|
|
def wolfram_string(path: Path) -> str:
|
|
"""
|
|
Превращает путь в безопасную строку Wolfram Language.
|
|
"""
|
|
s = str(path.resolve())
|
|
s = s.replace("\\", "\\\\").replace('"', '\\"')
|
|
return f'"{s}"'
|
|
|
|
|
|
def calculate_notebook(path: Path) -> bool:
|
|
print(f"\n{'=' * 70}")
|
|
print(f"Считаю: {path.name}")
|
|
print(f"{'=' * 70}")
|
|
|
|
nb_path = wolfram_string(path)
|
|
|
|
code = f'''
|
|
$HistoryLength = 0;
|
|
Print["Начало вычисления: {path.name}"];
|
|
NotebookEvaluate[
|
|
{nb_path},
|
|
InsertResults -> True
|
|
];
|
|
Print["Готово: {path.name}"];
|
|
Exit[];
|
|
'''
|
|
|
|
result = subprocess.call(["WolframKernel", "-nopromt", "-run", code])
|
|
return result == 0
|
|
|
|
calculate_notebook(Path("./notebook1.nb"))
|