Skip to content

Commit 0ab3b17

Browse files
author
Olivier Roques
committed
Update README.md
1 parent a269358 commit 0ab3b17

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ SSH library [paramiko](https://github.com/paramiko/paramiko/).
77
## Installation
88
Run:
99
```
10-
pip3 install --user sshcontroller-oroques
10+
pip3 install --user sshcontroller
1111
```
1212

13-
Note that the package has been exclusively tested on Python 3+.
13+
Note that the package has been exclusively tested on Python 3.6+.
1414

1515
## Usage
1616

17-
The code snippets can also be found at [demo.py](./examples/demo.py).
17+
All code snippets can also be found at [demo.py](./examples/demo.py).
1818

1919
#### 1. Create a new SSH controller from a SSH key
2020
```python
@@ -26,7 +26,7 @@ KEY_PWD = "password"
2626
ssh_controller = sshcontroller.SSHController(
2727
host=HOST_IP,
2828
user="olivier",
29-
key_path="~/.ssh/id_rsa", # if omitted, look in agent and in ~/.ssh
29+
key_path="~/.ssh/id_rsa", # if omitted, look for keys in SSH agent and in ~/.ssh/
3030
key_password=KEY_PWD, # optional
3131
key_type="rsa", # rsa (default), dsa, ecdsa or ed25519
3232
port=22, # 22 is the default
@@ -43,11 +43,11 @@ ssh_controller.connect()
4343
return_code, output = ssh_controller.run(
4444
command="echo 'Hello world!' > /tmp/hello.txt",
4545
display=True, # display output, false by default
46-
combine_stderr=False, # combine stderr and stdout, false by default
4746
capture_output=True, # return output, false by default
47+
combine_stderr=False, # combine stderr and stdout, false by default
4848
timeout=10, # command timeout in seconds, 600s by default
4949
)
50-
logging.info(f"return code: {return_code}, output: {output}")
50+
print(f"return code: {return_code}, output: {output}")
5151
```
5252

5353
#### 4. Transfer data with SFTP
@@ -56,10 +56,10 @@ All functions from paramiko's `SFTPClient` are available through the
5656
[paramiko's documentation](http://docs.paramiko.org/en/stable/api/sftp.html#paramiko.sftp_client.SFTPClient)
5757
for a complete list.
5858

59-
In addition, the package adds new methods:
59+
In addition, the package implements additional methods:
6060
* `exists(path)`: check that a file or a directory exists on the remote host
6161
* `list_dirs(path)`: return the list of directories present in `path`
62-
* `list_dirs(path)`: return the list of files present in `path`
62+
* `list_files(path)`: return the list of files present in `path`
6363

6464
```python
6565
print(f"hello.txt exists: {ssh_controller.exists('/tmp/hello.txt')}")
@@ -77,29 +77,29 @@ with open("/tmp/bonjour.txt", 'r') as bonjour:
7777
ssh_controller.disconnect()
7878
```
7979

80-
#### 6. Use SSH password instead
80+
#### 6. Use a SSH password instead of a key
8181
```python
8282
import sshcontroller
8383

8484
HOST_IP = "93.184.216.34" # an IPv4 or IPv6 address
85-
SSH_PWD = ""
85+
SSH_PWD = "password"
8686

8787
ssh_controller = sshcontroller.SSHController(
8888
host=HOST_IP,
89-
user="root",
89+
user="olivier",
9090
ssh_password=SSH_PWD
9191
)
9292
ssh_controller.connect()
9393
```
9494

9595
#### 7. Run a command until an event is set
96-
If the argument `stop_event` is set when calling `run()`, the controller waits
97-
for the given event to be triggered before stopping. This is especially useful
98-
when using threads.
96+
If the argument `stop_event` is set when calling `run()`, the controller
97+
ignores `timeout` and stops only when the given event is triggered instead.
98+
This is especially useful when using threads.
9999

100100
The example below starts two threads with an event attached to each one:
101101
one is pinging localhost, the other sleeps for 10s. When the sleeping threads
102-
has finished, we trigger the events to also stop the pinging thread.
102+
has finished, the events are triggered to also stop the pinging thread.
103103

104104
```python
105105
import logging
@@ -108,6 +108,8 @@ import sshcontroller
108108
import threading
109109
import time
110110

111+
# ... set up ssh_controller here ...
112+
111113
output = queue.Queue() # a queue to store the ping command output
112114
stop_event_sleep = threading.Event()
113115
stop_event_ping = threading.Event()

examples/demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def demo_key():
1616
ssh_controller = sshcontroller.SSHController(
1717
host=HOST_IP,
1818
user="olivier",
19-
key_path="~/.ssh/id_rsa", # if omitted, look in agent and in ~/.ssh
19+
key_path="~/.ssh/id_rsa", # if omitted, look for keys in SSH agent and in ~/.ssh/
2020
key_password=KEY_PWD, # optional
2121
key_type="rsa", # rsa (default), dsa, ecdsa or ed25519
2222
port=22, # 22 is the default
@@ -27,8 +27,8 @@ def demo_key():
2727
return_code, output = ssh_controller.run(
2828
command="echo 'Hello world!' > /tmp/hello.txt",
2929
display=True, # display output, false by default
30-
combine_stderr=False, # combine stderr and stdout, false by default
3130
capture_output=True, # return output, false by default
31+
combine_stderr=False, # combine stderr and stdout, false by default
3232
timeout=10, # command timeout in seconds, 600s by default
3333
)
3434
logging.info(f"return code: {return_code}, output: {output}")
@@ -48,7 +48,7 @@ def demo_key():
4848
def demo_pwd():
4949
ssh_controller = sshcontroller.SSHController(
5050
host=HOST_IP,
51-
user="root",
51+
user="olivier",
5252
ssh_password=SSH_PWD
5353
)
5454
ssh_controller.connect()

0 commit comments

Comments
 (0)