Skip to content

Instantly share code, notes, and snippets.

@KaiStarkk
Last active July 25, 2025 04:41
Show Gist options
  • Select an option

  • Save KaiStarkk/798671c5676fc18b9ed074a2e831b47b to your computer and use it in GitHub Desktop.

Select an option

Save KaiStarkk/798671c5676fc18b9ed074a2e831b47b to your computer and use it in GitHub Desktop.
r36sync - tool for synchronising local directory to the R36 handheld console
import os
import subprocess
from distutils.util import strtobool
def run_rsync(source, destination, dry_run=False):
"""
Run rsync command to sync files between source and destination.
"""
flags = "-avh --update --delete"
if dry_run:
flags += " --dry-run"
cmd = f"rsync {flags} {source}/ {destination}/"
result = subprocess.run(cmd, shell=True, capture_output=True, text=True)
return result.stdout
def sync_with_confirmation(pairs):
"""
Show dry-run output for each source-destination pair, ask for confirmation, and proceed with actual sync if confirmed.
"""
for source, destination in pairs.items():
print(f"\nPreview of changes from {source} to {destination}:")
dry_run_output = run_rsync(source, destination, dry_run=True)
print(dry_run_output)
print(f"\nPreview of changes from {destination} to {source}:")
dry_run_output = run_rsync(destination, source, dry_run=True)
print(dry_run_output)
try:
confirm = input("\nDo you want to proceed with the synchronization? (y/n): ").strip().lower()
if strtobool(confirm):
for source, destination in pairs.items():
print(f"\nSyncing from {source} to {destination}...")
print(run_rsync(source, destination))
print(f"\nSyncing from {destination} to {source}...")
print(run_rsync(destination, source))
print("\nSync complete.")
else:
print("\nSync canceled.")
except ValueError:
print("\nInvalid input. Sync canceled.")
if __name__ == "__main__":
sync_pairs = {
"/mnt/t/data/files": "/mnt/d/data/files",
"/mnt/t/config": "/mnt/d/config",
# Add more source-destination pairs as needed
}
sync_with_confirmation(sync_pairs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment