add logging and --dry-run

This commit is contained in:
stev 2023-09-11 22:39:05 +02:00
parent bbfb536b23
commit d437cdc479

View file

@ -1,3 +1,5 @@
from typing import Annotated
import logging
import typer
import subprocess
import shlex
@ -12,18 +14,31 @@ from gmirator import (
app = typer.Typer(help="syncs your files with configured remote")
@app.command("gmi")
def sync_gmi():
print("Synchronising GMI content with remote...")
print(f'rsync -aP -e "ssh -p {RPORT}" {DIR_SOURCE} {REM_GMI}')
subprocess.call(
shlex.split(f'rsync -aP -e "ssh -p {RPORT}" {DIR_SOURCE} {REM_GMI}')
)
print("Done!")
def sync_gmi(
dry_run: Annotated[
bool, typer.Option(help="dry runs the synchronisation")
] = False
):
logging.info(" Start synchronising GMI content with remote...")
sync_with_remote(RPORT, DIR_SOURCE, REM_GMI, dry_run)
logging.info(" Synchronisation of Gemini content with remote : done!")
@app.command("html")
def sync_html():
print("Synchronising HTML content with remote...")
def sync_html(
dry_run: Annotated[
bool, typer.Option(help="dry runs the synchronisation")
] = False
):
logging.info(" Start synchronising HTML content with remote...")
sync_with_remote(RPORT, DIR_O_HTML, REM_HTML, dry_run)
logging.info(" Synchronisation of HTML content with remote: done!")
def sync_with_remote(port: str, source, dest, dry_run: bool):
if dry_run:
rsync_command = f'rsync -aP --dry-run -e "ssh -p {port}" {source} {dest}'
else:
rsync_command = f'rsync -aP -e "ssh -p {port}" {source} {dest}'
logging.info(" " + rsync_command)
subprocess.call(
shlex.split(f'rsync -aP -e "ssh -p {RPORT}" {DIR_O_HTML} {REM_HTML}')
shlex.split(rsync_command)
)
print("Done!")