1
0
Fork 0
mirror of https://github.com/Findus23/rebound-collisions.git synced 2024-09-19 15:53:48 +02:00
rebound-collisions/utils/os_tools.py

40 lines
1.2 KiB
Python
Raw Normal View History

2021-04-05 17:57:45 +02:00
import os
import subprocess
from pathlib import Path
import socket
from sys import argv
from setproctitle import setproctitle
def filename_from_argv(argument: str = None) -> Path:
if len(argv) < 2:
raise ValueError("specify filename")
if argument:
fn = argument
else:
fn = argv[1]
fn = fn.replace(".bin", "").replace(".meta.json", "")
if fn.endswith("."):
fn = fn[:-1]
return Path(fn.replace(".bin", "").replace(".meta.json", ""))
def git_hash() -> str:
output = subprocess.run(["git", "rev-parse", "--verify", "HEAD"], capture_output=True)
return output.stdout.decode()
def check_heartbeat_needs_recompile() -> None:
library = Path("heartbeat/heartbeat.so")
code = library.with_suffix(".c")
if code.stat().st_mtime > library.stat().st_mtime:
raise RuntimeError("heartbeat.so is out of date. Please recompile it from source.")
def process_friendlyness(fn: Path) -> None:
if socket.gethostname() == "standpc":
# only handle other computers specially
return
setproctitle(f"[{fn.stem}] [rebound-watersim] read /home/winklerl23/sim-info.txt for more information")
os.nice(5)