-
Notifications
You must be signed in to change notification settings - Fork 2
/
rsync.py
32 lines (22 loc) · 932 Bytes
/
rsync.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import subprocess
import shlex
import ssh
import directorymonitor
_default_rsync_bin_path = '/usr/local/bin/rsync'
_default_rsync_options = '-Ccrlptv --exclude=/build*/ --exclude=/bin/ --exclude=.DS_Store --exclude=*.pyc --include=.git --del'
def run_rsync(localpath, remote_config, main, output=None):
sshconn = ssh.SSHConnectionDB().get(remote_config['remote_name'])
cmdline = _default_rsync_bin_path
# add ssh options
cmdline += " -e '%s'" % sshconn.ssh_build_cmdline(bare=True)
cmdline += " %s" % _default_rsync_options
cmdline += " %s/" % localpath
cmdline += " "
if sshconn.user is not None:
cmdline += "%s@" % sshconn.user
cmdline += "%s:%s/" % (sshconn.host, remote_config['remote_root'])
print "running [%s]" % cmdline
args = shlex.split(cmdline)
pipe = subprocess.Popen(args, stdout=output, stderr=output)
pipe.communicate()
return pipe.returncode