My package description
Project description
Targomiko
A wrapper for paramiko, focused on easy remote command handling of IO, waiting, abortion and exit-code retrieval.
It also brings along sane defaults for zero-user-interaction automation.
Installing
pip install targomiko
Examples
import time
import targomiko
with targomiko.SSHConnection("127.0.0.1", "user", password="password") as ssh:
ssh.upload_recursive(".", "/opt/targomiko")
# Do something with the underlying paramiko client
with ssh.client.open_sftp() as sftp:
sftp.mkdir("/opt/somedir")
# Execute command and wait for exit.
with ssh.exec('/opt/targomiko/entrypoint.sh arg1 "long arg 2"') as cmd:
cmd.wait()
print(f"Exit code: {cmd.exit_code}") # Will output something along the lines of "Exit code: 0"
# Execute command and abort after 1.5 seconds
with ssh.exec('/opt/targomiko/entrypoint.sh arg1 "long arg 2"') as cmd:
try:
cmd.wait(1.5)
except TimeoutError:
print("command timed out")
# Upon exit of the with, the command is aborted
print(f"Exit code: {cmd.exit_code}") # If the timeout was reached, will output "Exit code: -1"
# Execute command and abort after 1.5 seconds
with ssh.exec('/opt/targomiko/entrypoint.sh arg1 "long arg 2"') as cmd:
cmd.stdin.write("helo")
time.sleep(1)
# Preliminary output
print(f"STDOUT: {cmd.stdout}")
print(f"STDERR: {cmd.stderr}")
cmd.wait()
# Final, complete output
print(f"STDOUT: {cmd.stdout}")
print(f"STDERR: {cmd.stderr}")
print(f"Exit code: {cmd.exit_code}")
# You don't *have to* use a with-statement, but then remember to call close!
cmd = ssh.exec('/opt/targomiko/entrypoint.sh arg1 "long arg 2"')
try:
cmd.wait(1.5)
except TimeoutError:
print("command timed out")
finally:
cmd.close()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
targomiko-0.2.0.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for targomiko-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d48b0beddc31b579832a49883b9e8b5cc7cd899006cf990ed42437d5b7d4f914 |
|
MD5 | 5ef00f48876ee2964d0d7d9737ee23e0 |
|
BLAKE2b-256 | 7cac9ed4bee70e354ee89e6d7ea32e99d5945238db95961d2baa46f364b56859 |