diff options
| author | Jonas Devlieghere <jonas@devlieghere.com> | 2019-07-23 17:47:08 +0000 |
|---|---|---|
| committer | Jonas Devlieghere <jonas@devlieghere.com> | 2019-07-23 17:47:08 +0000 |
| commit | 93f505942c8091a3ebbf6f08764635f19dc79095 (patch) | |
| tree | 70a82c65c774eab5b060e2a2c39b0996d2c1a1cf /lldb/utils/sync-source/lib/transfer | |
| parent | ea5c94b497cfc43f9ec513f721e03aa5c669249a (diff) | |
| download | bcm5719-llvm-93f505942c8091a3ebbf6f08764635f19dc79095.tar.gz bcm5719-llvm-93f505942c8091a3ebbf6f08764635f19dc79095.zip | |
[Utils] Add back utils directory
Due to a bug my earlier commit removed the whole utils directory:
https://reviews.llvm.org/D65123
llvm-svn: 366830
Diffstat (limited to 'lldb/utils/sync-source/lib/transfer')
| -rw-r--r-- | lldb/utils/sync-source/lib/transfer/__init__.py | 0 | ||||
| -rw-r--r-- | lldb/utils/sync-source/lib/transfer/protocol.py | 8 | ||||
| -rw-r--r-- | lldb/utils/sync-source/lib/transfer/rsync.py | 61 | ||||
| -rw-r--r-- | lldb/utils/sync-source/lib/transfer/transfer_spec.py | 12 |
4 files changed, 81 insertions, 0 deletions
diff --git a/lldb/utils/sync-source/lib/transfer/__init__.py b/lldb/utils/sync-source/lib/transfer/__init__.py new file mode 100644 index 00000000000..e69de29bb2d --- /dev/null +++ b/lldb/utils/sync-source/lib/transfer/__init__.py diff --git a/lldb/utils/sync-source/lib/transfer/protocol.py b/lldb/utils/sync-source/lib/transfer/protocol.py new file mode 100644 index 00000000000..0f89db7d87e --- /dev/null +++ b/lldb/utils/sync-source/lib/transfer/protocol.py @@ -0,0 +1,8 @@ +class Protocol(object): + + def __init__(self, options, config): + self.options = options + self.config = config + + def transfer(transfer_specs, dry_run): + raise "transfer must be overridden by transfer implementation" 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..b90d108fca4 --- /dev/null +++ b/lldb/utils/sync-source/lib/transfer/rsync.py @@ -0,0 +1,61 @@ +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 diff --git a/lldb/utils/sync-source/lib/transfer/transfer_spec.py b/lldb/utils/sync-source/lib/transfer/transfer_spec.py new file mode 100644 index 00000000000..12da8b64aa2 --- /dev/null +++ b/lldb/utils/sync-source/lib/transfer/transfer_spec.py @@ -0,0 +1,12 @@ +class TransferSpec(object): + + def __init__(self, source_path, exclude_paths, dest_path): + self.source_path = source_path + self.exclude_paths = exclude_paths + self.dest_path = dest_path + + def __repr__(self): + fmt = ( + "TransferSpec(source_path='{}', exclude_paths='{}', " + "dest_path='{}')") + return fmt.format(self.source_path, self.exclude_paths, self.dest_path) |

