mirror of
https://github.com/dredx/prole.git
synced 2026-09-23 11:03:59 +00:00
- Add build-context helper to copy Docker context safely (ignore runtime data, keep symlinks) - Update UI and core actions to use ~/.prole/build and shared copy helper - Add/adjust tests and scripts; introduce knoe ops helpers and update manifests Co-authored-by: Junie <junie@jetbrains.com>
50 lines
1014 B
Python
50 lines
1014 B
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import shutil
|
|
from pathlib import Path
|
|
|
|
|
|
def ensure_dir(path: Path) -> None:
|
|
path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
def write_if_changed(path: Path, text: str, *, encoding: str = "utf-8") -> bool:
|
|
existing = None
|
|
try:
|
|
existing = path.read_text(encoding=encoding)
|
|
except Exception:
|
|
existing = None
|
|
|
|
if existing == text:
|
|
return False
|
|
|
|
ensure_dir(path.parent)
|
|
path.write_text(text, encoding=encoding)
|
|
return True
|
|
|
|
|
|
def copy_if_changed(src: Path, dst: Path) -> bool:
|
|
try:
|
|
if dst.exists() and src.read_bytes() == dst.read_bytes():
|
|
return False
|
|
except Exception:
|
|
pass
|
|
|
|
ensure_dir(dst.parent)
|
|
shutil.copy2(src, dst)
|
|
return True
|
|
|
|
|
|
def chmod_if_needed(path: Path, mode: int) -> bool:
|
|
try:
|
|
current = path.stat().st_mode & 0o777
|
|
except Exception:
|
|
return False
|
|
|
|
if current == mode:
|
|
return False
|
|
|
|
os.chmod(path, mode)
|
|
return True
|