diff --git a/README.md b/README.md index ff95619..def0e63 100644 --- a/README.md +++ b/README.md @@ -41,18 +41,15 @@ ssh_controller.connect() #### 3. Run a command ```python -return_code, output = ssh_controller.run( +exit_code, output = ssh_controller.run( command="echo 'Hello world!' > /tmp/hello.txt", - display=True, # display output, false by default - capture=True, # save output, false by default - # request a shell to run the command, true by default - shell=True, - # combine stderr into stdout when shell=False, false by default - combine_stderr=False, - # command timeout in seconds, None (wait indefinitely) by default - timeout=10, + display=True, # display output, disabled by default + capture=True, # save output, disabled by default + shell=True, # request a shell to run the command, enabled by default + combine_stderr=False, # combine stderr into stdout when shell=False, disabled by default + timeout=10, # command timeout in seconds, None (wait indefinitely) by default ) -print(f"return code: {return_code}, output: {output}") +print(f"exit code: {exit_code}, output: {output}") ``` #### 4. Transfer data with SFTP @@ -98,13 +95,13 @@ ssh_controller.connect() ``` #### 7. Run a command until an event is set -If the argument `stop_event` is set when calling `run()`, the controller -ignores `timeout` and stops only when the given event is triggered instead. -This is especially useful when using threads. +If the argument `stop_event` (a `threading.Event` object) is set when +calling `run()`, the controller ignores `timeout` and stops when the given +event is triggered instead. This is especially useful when using threads. The example below starts two threads with an event attached to each one: -one is pinging localhost, the other sleeps for 10s. When the sleeping threads -has finished, the events are triggered to also stop the pinging thread. +one is pinging `localhost`, the other sleeps for 10s. When the sleeping thread +has finished, events are triggered to also stop the pinging thread. ```python import logging @@ -153,8 +150,8 @@ finally: stop_event_ping.set() time.sleep(2) -return_code, ping_output = output.get() -logging.info(f"thread ping return code: {return_code}") +exit_code, ping_output = output.get() +logging.info(f"thread ping exit code: {exit_code}") logging.info(f"thread ping output length: {len(ping_output)}") ssh_controller.disconnect() diff --git a/examples/demo.py b/examples/demo.py index eff1998..95d1f85 100755 --- a/examples/demo.py +++ b/examples/demo.py @@ -19,23 +19,23 @@ def demo_key(): key_path="~/.ssh/id_rsa", # if omitted, look in agent and in ~/.ssh/ key_password=KEY_PWD, # optional key_type="rsa", # rsa (default), dsa, ecdsa or ed25519 - port=22, # 22 is the default + port=22, # 22 by default ) ssh_controller.connect() - return_code, output = ssh_controller.run( + exit_code, output = ssh_controller.run( command="echo 'Hello world!' > /tmp/hello.txt", - display=True, # display output, false by default - capture=True, # save output, false by default - # request a shell to run the command, true by default + display=True, # display output, disabled by default + capture=True, # save output, disabled by default + # request a shell to run the command, enabled by default shell=True, - # combine stderr into stdout when shell=False, false by default + # combine stderr into stdout when shell=False, disabled by default combine_stderr=False, # command timeout in seconds, None (wait indefinitely) by default timeout=10, ) - logging.info(f"return code: {return_code}, output: {output}") + logging.info(f"exit code: {exit_code}, output: {output}") print(f"hello.txt exists: {ssh_controller.exists('/tmp/hello.txt')}") print(f"bonjour.txt exists: {ssh_controller.exists('/tmp/bonjour.txt')}") @@ -95,8 +95,8 @@ def wrapper(kwargs): stop_event_ping.set() time.sleep(2) - return_code, ping_output = output.get() - logging.info(f"thread ping return code: {return_code}") + exit_code, ping_output = output.get() + logging.info(f"thread ping exit code: {exit_code}") logging.info(f"thread ping output length: {len(ping_output)}") ssh_controller.disconnect() diff --git a/setup.py b/setup.py index 39423c9..2159909 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="sshcontroller", - version="1.3", + version="1.4", author="Olivier Roques", author_email="olivier@oroques.dev", description="A package to easily run SSH commands", @@ -23,4 +23,5 @@ "Topic :: Software Development", ], python_requires='>=3.6', + install_requires=['paramiko'], )