marc/sync.py
2025-02-22 20:56:41 +01:00

78 lines
2.2 KiB
Python
Executable file

#! /usr/bin/env python3
"""Synchronize to remote pubnixes."""
from __future__ import annotations
from logging import log
from os import sep
from pathlib import Path
from pubnix import PubNix
import subprocess
ARGS = [
{
"dn": "blinkenshell.org",
"ssh": "ssh",
"port": 2222,
"web": "u",
"sub": True,
},
{"dn": "ctrl-c.club", "sub": False},
{"dn": "dimension.sh", "sub": True},
{"dn": "envs.net", "sub": True},
{"dn": "freeshell.de", "sub": False},
{"dn": "insomnia247.nl", "dir": True, "sub": True},
{"dn": "p.projectsegfau.lt", "sub": True},
{"dn": "rawtext.club", "sub": False},
{"dn": "rw.rs", "sub": False},
{"dn": "thunix.net", "sub": False},
{"dn": "tilde.32bit.cafe", "root": "www", "sub": False},
{"dn": "tilde.cafe", "sub": True},
{"dn": "tilde.club", "sub": False},
{"dn": "tilde.fun", "root": "html", "sub": False},
{"dn": "tilde.green", "sub": False},
{"dn": "tilde.guru", "sub": False},
{"dn": "tilde.institute", "sub": True},
{"dn": "tilde.pink", "sub": False},
{"dn": "tilde.team", "sub": True},
{"dn": "tilde.town", "sub": False},
# old
{"dn": "fr.tild3.org", "sub": True},
{"dn": "remotes.club", "port": 9022, "root": "web", "sub": True},
{"dn": "squiggle.city", "sub": False},
]
PUBNIXES = [PubNix(**args) for args in ARGS]
def sync(root: Path, pubnix: PubNix, exclude: list[str] | None = None) -> None:
"""Synchronize local root directory with pubnix."""
args = [
"rsync",
"--archive",
"--checksum",
"--delete-before",
"--rsh",
f"ssh -o 'LogLevel Error' -p {pubnix.port}",
"--partial",
"--progress",
"--verbose",
f"{root}{sep}",
]
if exclude:
for item in exclude:
args.extend(["--exclude", f"{sep}{item}"])
args.append(f"{pubnix.target}{sep}")
subprocess.call(args, stdout=subprocess.DEVNULL)
def main() -> None:
"""Synchronize content on remote pubnixes."""
root = Path(__file__).resolve().parent / "out" / "web"
for pn in PUBNIXES:
log()
log(pn)
sync(root, pn, exclude=["__pycache__", "pgp.asc"])
if __name__ == "__main__":
main()