save a file to alocal folder and make it executable

This commit is contained in:
Stanislas Jouffroy 2025-03-04 00:06:09 +01:00
parent e54626d971
commit 230cf99f06
8 changed files with 122 additions and 21 deletions

17
majordome/local_files.py Normal file
View file

@ -0,0 +1,17 @@
from pathlib import Path
def save(destination: Path, file_content: bytes):
destination.parent.mkdir(parents=True, exist_ok=True)
destination.write_bytes(file_content)
def set_execution_rights(file: Path):
file_rights = file.stat().st_mode
rights_to_set = file_rights | 0o111
file.chmod(rights_to_set)
def save_and_make_executable(destination: Path, content: bytes):
save(destination, content)
set_execution_rights(destination)