diff options
author | Lars Wirzenius <liw@liw.fi> | 2013-06-09 14:02:37 +0100 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2013-06-09 14:02:37 +0100 |
commit | 77de905c50bb3bcbbd4c41a841745e5e1b9c1d0f (patch) | |
tree | 77f23fc9825d867153ba68e6d859ef88c9b15cfe | |
parent | 7671fc78cb1f6e26cf7ad29e8bd51743ff2e828e (diff) | |
parent | 99389f75ae0b9ab594f8b7e7bfc0fe255b512900 (diff) | |
download | cliapp-77de905c50bb3bcbbd4c41a841745e5e1b9c1d0f.tar.gz |
Merged ssh_runcmd tty option from Jannis Pohlmann
-rw-r--r-- | NEWS | 2 | ||||
-rw-r--r-- | cliapp/runcmd.py | 25 |
2 files changed, 26 insertions, 1 deletions
@@ -6,6 +6,8 @@ Version 1.UNRELEASED * cliapp(5) now mentions subcommands and the automatic subcommand "help". +* `ssh_runcmd` now has the `tty` keyword argument to enable ssh + allocation of pseudo-TTYs. Patch from Jannis Pohlmann. Version 1.20130424 ------------------ diff --git a/cliapp/runcmd.py b/cliapp/runcmd.py index 41878f5..7565bbd 100644 --- a/cliapp/runcmd.py +++ b/cliapp/runcmd.py @@ -242,6 +242,19 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover machine. The command is given as an argv array; elements in the array are automatically quoted so they get passed to the other side correctly. + + An optional ``tty=`` parameter can be passed to ``ssh_runcmd`` in + order to force or disable pseudo-tty allocation. This is often + required to run ``sudo`` on another machine and might be useful + in other situations as well. Supported values are ``tty=True`` for + forcing tty allocation, ``tty=False`` for disabling it and + ``tty=None`` for not passing anything tty related to ssh. + + With the ``tty`` option, + ``cliapp.runcmd(['ssh', '-tt', 'user@host', '--', 'sudo', 'ls'])`` + can be written as + ``cliapp.ssh_runcmd('user@host', ['sudo', 'ls'], tty=True)`` + which is more intuitive. The target is given as-is to ssh, and may use any syntax ssh accepts. @@ -255,6 +268,16 @@ def ssh_runcmd(target, argv, **kwargs): # pragma: no cover ''' - local_argv = ['ssh', target, '--'] + map(shell_quote, argv) + tty = kwargs.get('tty', None) + if tty: + ssh_cmd = ['ssh', '-tt', target, '--'] + elif tty is False: + ssh_cmd = ['ssh', '-T', target, '--'] + else: + ssh_cmd = ['ssh', target, '--'] + if 'tty' in kwargs: + del kwargs['tty'] + + local_argv = ssh_cmd + map(shell_quote, argv) return runcmd(local_argv, **kwargs) |