diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-03-24 20:01:44 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-03-24 20:01:44 +0200 |
commit | 8025fd6198bd9a5ff40cb3acd110408c5e7b27be (patch) | |
tree | 63acba2100a7b6e760f7c3bccfa085b3d2f69057 | |
parent | 569df8a5959cd8ef46f78c9497461240a5aa1123 (diff) | |
parent | 17eb28a1cd1c20fd304361b24eb6e20dfe9c8ebe (diff) | |
download | cliapp-8025fd6198bd9a5ff40cb3acd110408c5e7b27be.tar.gz |
Add ssh_options to ssh_runcmd
-rw-r--r-- | NEWS | 6 | ||||
-rw-r--r-- | cliapp/runcmd.py | 26 |
2 files changed, 23 insertions, 9 deletions
@@ -1,6 +1,12 @@ NEWS for cliapp =============== +Version 1.UNRELEASED +------------------ + +* Lars Wirzenius added the `ssh_options` keyword argument to + `cliapp.ssh_runcmd`. + Version 1.20150305 ------------------ diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py index 5ac8da5..2780755 100644 --- a/cliapp/runcmd.py +++ b/cliapp/runcmd.py @@ -293,6 +293,11 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover ``cliapp.ssh_runcmd('user@host', ['sudo', 'ls'], tty=True)`` which is more intuitive. + Arbitrary command line options to the ssh command can be given + with the ``ssh_options`` argument. For example: + ``cliapp.ssh_runcmd( + 'user@host', ['sudo', 'ls'], ssh_options=['-oStrictHostChecking=no'])`` + The target is given as-is to ssh, and may use any syntax ssh accepts. @@ -305,16 +310,19 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover ''' - tty = kwargs.get('tty', None) + ssh_argv = ['ssh'] + + tty = kwargs.pop('tty', None) if tty: - ssh_cmd = ['ssh', '-tt', target, '--'] + ssh_argv.append('-tt') elif tty is False: - ssh_cmd = ['ssh', '-T', target, '--'] - else: - ssh_cmd = ['ssh', target, '--'] - if 'tty' in kwargs: - del kwargs['tty'] + ssh_argv.append('-T') - local_argv = ssh_cmd + map(shell_quote, argv) - return runcmd(local_argv, **kwargs) + more_options = kwargs.pop('ssh_options', []) + ssh_argv.extend(more_options) + + ssh_argv.append(target) + ssh_argv.append('--') + local_argv = ssh_argv + map(shell_quote, argv) + return runcmd(local_argv, **kwargs) |