diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-03-24 21:54:29 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-03-24 21:54:29 +0200 |
commit | 6d7daee29388fb3520cd70ed3cf0a4c085f80f69 (patch) | |
tree | 21f5a1a61c7743767f4e99cb7bff2ad04c0646a9 | |
parent | 891931ae14b8acac72d49e6323eb3727458266a4 (diff) | |
download | cliapp-6d7daee29388fb3520cd70ed3cf0a4c085f80f69.tar.gz |
Add ssh_runcmd(..., remote_cwd='...'))
-rw-r--r-- | NEWS | 8 | ||||
-rw-r--r-- | cliapp/runcmd.py | 11 |
2 files changed, 18 insertions, 1 deletions
@@ -5,7 +5,13 @@ Version 1.UNRELEASED ------------------ * Lars Wirzenius added the `ssh_options` keyword argument to - `cliapp.ssh_runcmd`. + `cliapp.ssh_runcmd` to allow adding command line options to the ssh + program. + +* Lars Wirzenius added the `remote_cwd` keyword argument to + `cliapp.ssh_runcmd` to allow the caller to easily change to a + directory on the server. + Version 1.20150305 ------------------ diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py index b74f781..ffd120d 100644 --- a/cliapp/runcmd.py +++ b/cliapp/runcmd.py @@ -298,6 +298,10 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover ``cliapp.ssh_runcmd( 'user@host', ['sudo', 'ls'], ssh_options=['-oStrictHostChecking=no'])`` + The remote command is run in the user's home directory, by + default. The directory can be changed with the keyword argument + ``remote_cwd``. + The target is given as-is to ssh, and may use any syntax ssh accepts. @@ -324,5 +328,12 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover ssh_argv.append(target) ssh_argv.append('--') + remote_cwd = kwargs.pop('remote_cwd', None) + if remote_cwd: + ssh_argv.extend(map(shell_quote, [ + 'sh', '-c', 'cd "$1" && shift && exec "$@"', + '-', + remote_cwd])) + local_argv = ssh_argv + map(shell_quote, argv) return runcmd(local_argv, **kwargs) |