Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sudo_command(self):
command = make_command('uptime', sudo=True)
self.assertEqual(command, 'sudo -H sh -c uptime')
def test_custom_shell_command(self):
command = make_command('uptime', shell_executable='bash')
self.assertEqual(command, 'bash -c uptime')
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
command (string): actual command to execute
sudo (boolean): whether to wrap the command with sudo
sudo_user (string): user to sudo to
get_pty (boolean): whether to get a PTY before executing the command
env (dict): envrionment variables to set
timeout (int): timeout for this command to complete before erroring
Returns:
tuple: (exit_code, stdout, stderr)
stdout and stderr are both lists of strings from each buffer.
'''
command = make_command(command, **command_kwargs)
logger.debug('--> Running command on localhost: {0}'.format(command))
if print_output:
print('{0}>>> {1}'.format(host.print_prefix, command))
process = Popen(command, shell=True, stdout=PIPE, stderr=PIPE)
combined_output = read_buffers_into_queue(
host,
process.stdout,
process.stderr,
timeout=timeout,
print_output=print_output,
)
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
command (string): actual command to execute
sudo (boolean): whether to wrap the command with sudo
sudo_user (string): user to sudo to
get_pty (boolean): whether to get a PTY before executing the command
env (dict): envrionment variables to set
timeout (int): timeout for this command to complete before erroring
Returns:
tuple: (exit_code, stdout, stderr)
stdout and stderr are both lists of strings from each buffer.
'''
command = make_command(command, **command_kwargs)
logger.debug('Running command on {0}: (pty={1}) {2}'.format(
host.name, get_pty, command,
))
if print_output:
print('{0}>>> {1}'.format(host.print_prefix, command))
# Run it! Get stdout, stderr & the underlying channel
_, stdout_buffer, stderr_buffer = host.connection.exec_command(
command,
get_pty=get_pty,
)
combined_output = read_buffers_into_queue(
host,
Args:
state (``pyinfra.api.State`` obj): state object for this command
hostname (string): hostname of the target
command (string): actual command to execute
sudo (boolean): whether to wrap the command with sudo
sudo_user (string): user to sudo to
get_pty (boolean): whether to get a PTY before executing the command
env (dict): envrionment variables to set
timeout (int): timeout for this command to complete before erroring
Returns:
tuple: (exit_code, stdout, stderr)
stdout and stderr are both lists of strings from each buffer.
'''
command = make_command(
command,
env=env,
sudo=sudo,
sudo_user=sudo_user,
su_user=su_user,
preserve_sudo_env=preserve_sudo_env,
)
logger.debug('Running command on {0}: {1}'.format(host.name, command))
if print_output:
print('{0}>>> {1}'.format(host.print_prefix, command))
# Run it! Get stdout, stderr & the underlying channel
_, stdout_buffer, stderr_buffer = host.connection.exec_command(
command,