Skip to content

Commit

Permalink
Use rsync to make dripbox easier to use
Browse files Browse the repository at this point in the history
  • Loading branch information
epall committed Jan 30, 2011
1 parent 76d063e commit bfaf9f4
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions scripts/drip
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import argparse
import sys
import os
import getpass
import subprocess

LOG_FORMAT = "%(asctime)s - %(levelname)s - %(message)s"
REMOTE_MATCH = re.compile("(.+@)?(.+):(.+)").match
Expand All @@ -36,6 +37,10 @@ parser = argparse.ArgumentParser(
parser.add_argument('-p', '--remote-port',
type=int, help="SSH port on remote system")
parser.add_argument('remote', nargs=1, metavar="USER@HOST:PATH")
parser.add_argument('-s', '--sync', action="store_true", default=False,
help="Synchronize local to remote using rsync at start")
parser.add_argument('-f', '--force', action="store_true", default=False,
help="Force dripbox to start even with a dirty remote")
args = parser.parse_args()


Expand All @@ -50,6 +55,35 @@ def parse_remote(remote):

launch_args = parse_remote(args.remote[0])
launch_args['port'] = args.remote_port

port = args.remote_port or 22
if args.sync:
command = ["rsync", "--delete", "-rltvze", "ssh -p%s" % port, "--exclude",
".git", ".", args.remote[0]]
subprocess.check_call(command)
else:
diff = subprocess.Popen(
["rsync", "--delete", "-crnltvze", "ssh -p%s" % port, "--exclude",
".git", ".", args.remote[0]],
stdout=subprocess.PIPE)
output, _ = diff.communicate()
for line in output.split("\n"):
if line == "":
pass
elif line == "sending incremental file list":
pass
elif re.match("sent \d+ bytes +received \d+ bytes [0-9\.]+ bytes/sec", line):
pass
elif re.search("total size is \d+ +speedup is [0-9\.]", line):
pass
else:
print "WARNING: The remote tree is out of sync with the local tree. This is a dangerous situation."
if not args.force:
print "Run dripbox with -f if you know what you're doing and want to run dripbox anyway"
print "We recommend you use --sync instead."
raise SystemExit(1)
break

dripbox.launch(**launch_args)

print("Hit ENTER to quit")
Expand Down

0 comments on commit bfaf9f4

Please sign in to comment.