marc/sync.py

79 lines
2.2 KiB
Python
Raw Normal View History

2022-05-01 22:58:23 +02:00
#! /usr/bin/env python3
2025-02-22 20:56:41 +01:00
"""Synchronize to remote pubnixes."""
2022-05-01 22:58:23 +02:00
2025-02-22 20:56:41 +01:00
from __future__ import annotations
2025-02-18 22:05:22 +01:00
from logging import log
2025-02-22 20:56:41 +01:00
from os import sep
2025-02-18 22:05:22 +01:00
from pathlib import Path
2025-02-22 20:34:26 +01:00
from pubnix import PubNix
2025-02-22 20:56:41 +01:00
import subprocess
2022-05-01 22:58:23 +02:00
ARGS = [
2025-02-18 20:58:05 +01:00
{
"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},
2023-10-08 15:00:44 +02:00
# old
2025-02-18 20:58:05 +01:00
{"dn": "fr.tild3.org", "sub": True},
{"dn": "remotes.club", "port": 9022, "root": "web", "sub": True},
{"dn": "squiggle.city", "sub": False},
2022-05-01 22:58:23 +02:00
]
2025-02-22 20:34:26 +01:00
PUBNIXES = [PubNix(**args) for args in ARGS]
2022-05-01 22:58:23 +02:00
2025-02-22 20:56:41 +01:00
def sync(root: Path, pubnix: PubNix, exclude: list[str] | None = None) -> None:
2025-02-22 20:34:26 +01:00
"""Synchronize local root directory with pubnix."""
2022-05-01 22:58:23 +02:00
args = [
2025-02-18 20:58:05 +01:00
"rsync",
"--archive",
"--checksum",
"--delete-before",
"--rsh",
f"ssh -o 'LogLevel Error' -p {pubnix.port}",
"--partial",
"--progress",
"--verbose",
2025-02-22 20:56:41 +01:00
f"{root}{sep}",
2022-05-01 22:58:23 +02:00
]
2025-02-22 20:56:41 +01:00
if exclude:
for item in exclude:
args.extend(["--exclude", f"{sep}{item}"])
args.append(f"{pubnix.target}{sep}")
2022-05-01 22:58:23 +02:00
subprocess.call(args, stdout=subprocess.DEVNULL)
2025-02-18 22:05:22 +01:00
def main() -> None:
"""Synchronize content on remote pubnixes."""
2025-02-22 20:56:41 +01:00
root = Path(__file__).resolve().parent / "out" / "web"
2025-02-18 21:16:35 +01:00
for pn in PUBNIXES:
log()
log(pn)
sync(root, pn, exclude=["__pycache__", "pgp.asc"])
2022-05-01 22:58:23 +02:00
2025-02-18 20:58:05 +01:00
if __name__ == "__main__":
2022-05-01 22:58:23 +02:00
main()