Skip to main content

CLImatic

License PyPI versions

CLImatic is tool to ease and automate CLI usage. It abstracts the CLI connection for you and you just need to send commands and process the returned results.

Install

Install the last stable release from PyPI using pip or easy_install:

> pip3 install climatic

Or install the latest sources from Github:

> pip3 install -e git+git://github.com/evedovelli/climatic.git#egg=climatic

Usage

Import the CLImatic CLI client, open the connection, and run commands. That's all!

from climatic.cli.Linux import SshLinux

cmd = SshLinux("127.0.0.1", "your.user", "your.password")
cmd.run("mkdir /tmp/test")
cmd.run("ls /tmp/")

And what if you need to check the outputs of the commands?

That's easy! Well, some basic validations are already made inside the run method. It verifies if the command hangs, or if and error_marker is outputed.

Besides, the run method returns you the outputs of the command which you can use to make any validation you'd like. When used with the expects library (or with the assertion library of your preference), it becomes a powerfull tool to write TDD/BDD tests for CLIs. Take a look at this example:

from climatic.cli.Linux import SshLinux
from expects import *

cmd = SshLinux("127.0.0.1", "your.user", "your.password")

cmd.run("mkdir /tmp/test")

# In an expressive manner, you can test if the cmd run output contains a specific term:
expect(cmd.run("ls /tmp/").output).to(contain("test"))

cmd.run("rm -r /tmp/test")

# Or if it does not contain it:
expect(cmd.run("ls /tmp/").output).not_to(contain("test"))

# You can also verify the duration of a command run:
expect(cmd.run("sleep 2").duration).to(be_below(3))
expect(cmd.run("sleep 3").duration).to(be_above(2))

Read the expects docs for discovering other matchers or how to build your own.

Also, instead of run you can call the cli method. In this case you pass as argument a complete CLI session, and the command will parse the commands, execute them, and match the outputs. Like this:

from climatic.cli.Linux import SshLinux
from expects import *

cmd = SshLinux("127.0.0.1", "your.user", "your.password")

# Run the commands line by line and expect for outputs
# for the lines without the shell marker:
cmd.cli("""
    ~# mkdir /tmp/test
    ~# ls /tmp/
    test
    ~# rm -rv /tmp/test
    removed directory '/tmp/test'
    """)

CLImatic includes only a few built-in CLI clients, as the Linux client from the example above, but you will find many other CLI clients extensions. There a list with supported CLI clients in here.

In this example, we are accessing and running commands in a remote python3 CLI through a SSH connection with CLImatic-Python client:

from climatic_python.Python3Shell import SshPython3Shell

python_cmd = SshPython3Shell("127.0.0.1", "your.user", "your.password")
python_cmd.run("""
i = 3
for x in range(i):
    print("Iteration {}".format(x))

""")

List of CLI Clients

Metadata

Release files for climatic 0.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for climatic 0.0.4
File Size Uploaded Provenance Actions
climatic-0.0.4.tar.gz 13.1 kB Without provenance Details for climatic-0.0.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for climatic 0.0.4
File Interpreter ABI Platform Actions
climatic-0.0.4-py3-none-any.whl Python 3 none any Details for climatic-0.0.4-py3-none-any.whl

Total release size: 27.5 kB

Release files / climatic-0.0.4.tar.gz

Download URL climatic-0.0.4.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b63cfc652cf78289b633e81c827402765fb6f91d017a59c35bb41383b644b783
BLAKE2b-256 checksum
How to use checksums
429935adbe7ce0aa328b576a651f59d82f5c82bc7ebdeac48aea8e8277b3f969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.22.0 requests-toolbelt/0.8.0 urllib3/1.26.8 tqdm/4.57.0 importlib-metadata/3.9.0 keyring/18.0.1 rfc3986/1.4.0 colorama/0.4.3 CPython/3.8.10

Release files / climatic-0.0.4-py3-none-any.whl

Download URL climatic-0.0.4-py3-none-any.whl
Size 14.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d26c84d70dab41c61d8875d56cc5ac5c0f60ae926640d3168d68beb58a4c682f
BLAKE2b-256 checksum
How to use checksums
56ce02c53c7a604f5845137e65fb33d5abae9bfb948146d7e73ff8ff2542a572
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/28.0 requests/2.22.0 requests-toolbelt/0.8.0 urllib3/1.26.8 tqdm/4.57.0 importlib-metadata/3.9.0 keyring/18.0.1 rfc3986/1.4.0 colorama/0.4.3 CPython/3.8.10

Security for climatic 0.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page