This commit is contained in:
Marc Beninca 2025-02-22 20:56:41 +01:00
parent 77e12933fd
commit 6a985e0b89
Signed by: marc.beninca
GPG key ID: 9C7613450C80C24F

20
sync.py
View file

@ -1,10 +1,13 @@
#! /usr/bin/env python3 #! /usr/bin/env python3
"""Synchronize to remote pubnixes."""
import os from __future__ import annotations
import subprocess
from logging import log from logging import log
from os import sep
from pathlib import Path from pathlib import Path
from pubnix import PubNix from pubnix import PubNix
import subprocess
ARGS = [ ARGS = [
{ {
@ -41,7 +44,7 @@ ARGS = [
PUBNIXES = [PubNix(**args) for args in ARGS] PUBNIXES = [PubNix(**args) for args in ARGS]
def sync(root: str, pubnix: PubNix, exclude: list[str] | None = None) -> None: def sync(root: Path, pubnix: PubNix, exclude: list[str] | None = None) -> None:
"""Synchronize local root directory with pubnix.""" """Synchronize local root directory with pubnix."""
args = [ args = [
"rsync", "rsync",
@ -53,17 +56,18 @@ def sync(root: str, pubnix: PubNix, exclude: list[str] | None = None) -> None:
"--partial", "--partial",
"--progress", "--progress",
"--verbose", "--verbose",
os.path.join(root, ""), f"{root}{sep}",
] ]
for item in exclude: if exclude:
args.extend(["--exclude", os.path.join("", item)]) for item in exclude:
args.append(os.path.join(pubnix.target, "")) args.extend(["--exclude", f"{sep}{item}"])
args.append(f"{pubnix.target}{sep}")
subprocess.call(args, stdout=subprocess.DEVNULL) subprocess.call(args, stdout=subprocess.DEVNULL)
def main() -> None: def main() -> None:
"""Synchronize content on remote pubnixes.""" """Synchronize content on remote pubnixes."""
root = Path(os.path.realpath(__file__)).parent / "out" / "web" root = Path(__file__).resolve().parent / "out" / "web"
for pn in PUBNIXES: for pn in PUBNIXES:
log() log()
log(pn) log(pn)