diff options
author | Todd Fiala <todd.fiala@gmail.com> | 2015-09-17 17:14:31 +0000 |
---|---|---|
committer | Todd Fiala <todd.fiala@gmail.com> | 2015-09-17 17:14:31 +0000 |
commit | 37e56318ec2e4a08974fedd99cfacbe7b9613392 (patch) | |
tree | ec27e11c64383fc810f845b87e064ee1cd962e93 /lldb/utils/sync-source/lib/transfer/rsync.py | |
parent | 01485654db8031fcc94158a437fdf23c4fdfe97a (diff) | |
download | bcm5719-llvm-37e56318ec2e4a08974fedd99cfacbe7b9613392.tar.gz bcm5719-llvm-37e56318ec2e4a08974fedd99cfacbe7b9613392.zip |
Add sync-source.py utility.
See:
http://reviews.llvm.org/D12940
for more details.
See utils/sync-source/README.txt for documentation
and a sample .sync-sourcerc file.
llvm-svn: 247903
Diffstat (limited to 'lldb/utils/sync-source/lib/transfer/rsync.py')
-rw-r--r-- | lldb/utils/sync-source/lib/transfer/rsync.py | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/lldb/utils/sync-source/lib/transfer/rsync.py b/lldb/utils/sync-source/lib/transfer/rsync.py new file mode 100644 index 00000000000..7a89344b699 --- /dev/null +++ b/lldb/utils/sync-source/lib/transfer/rsync.py @@ -0,0 +1,60 @@ +import os.path +import pprint +import subprocess +import sys + +import transfer.protocol + + +class RsyncOverSsh(transfer.protocol.Protocol): + def __init__(self, options, config): + super(RsyncOverSsh, self).__init__(options, config) + self.ssh_config = config.get_value("ssh") + + def build_rsync_command(self, transfer_spec, dry_run): + dest_path = os.path.join( + self.ssh_config["root_dir"], + transfer_spec.dest_path) + flags = "-avz" + if dry_run: + flags += "n" + cmd = [ + "rsync", + flags, + "-e", + "ssh -p {}".format(self.ssh_config["port"]), + "--rsync-path", + # The following command needs to know the right way to do + # this on the dest platform - ensures the target dir exists. + "mkdir -p {} && rsync".format(dest_path) + ] + + # Add source dir exclusions + if transfer_spec.exclude_paths: + for exclude_path in transfer_spec.exclude_paths: + cmd.append("--exclude") + cmd.append(exclude_path) + + cmd.extend([ + "--delete", + transfer_spec.source_path + "/", + "{}@{}:{}".format( + self.ssh_config["user"], + self.ssh_config["dest_host"], + dest_path)]) + return cmd + + def transfer(self, transfer_specs, dry_run): + if self.options.verbose: + printer = pprint.PrettyPrinter() + for spec in transfer_specs: + printer.pprint(spec) + + for spec in transfer_specs: + cmd = self.build_rsync_command(spec, dry_run) + if self.options.verbose: + print "executing the following command:\n{}".format(cmd) + result = subprocess.call( + cmd, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr) + if result != 0: + return result |