diff --git a/src/gmirator/synchronise.py b/src/gmirator/synchronise.py index 2dbf4ec..b669f36 100644 --- a/src/gmirator/synchronise.py +++ b/src/gmirator/synchronise.py @@ -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!")