Skip to main content

Tool to ease and automate CLI usage

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

climatic-0.0.4.tar.gz (13.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

climatic-0.0.4-py3-none-any.whl (14.4 kB view details)

Uploaded Python 3

File details

Details for the file climatic-0.0.4.tar.gz.

File metadata

  • Download URL: climatic-0.0.4.tar.gz
  • Upload date:
  • Size: 13.1 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for climatic-0.0.4.tar.gz
Algorithm Hash digest
SHA256 b63cfc652cf78289b633e81c827402765fb6f91d017a59c35bb41383b644b783
MD5 57a296557eb475e53f8ca5062520d4bf
BLAKE2b-256 429935adbe7ce0aa328b576a651f59d82f5c82bc7ebdeac48aea8e8277b3f969

See more details on using hashes here.

File details

Details for the file climatic-0.0.4-py3-none-any.whl.

File metadata

  • Download URL: climatic-0.0.4-py3-none-any.whl
  • Upload date:
  • Size: 14.4 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for climatic-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d26c84d70dab41c61d8875d56cc5ac5c0f60ae926640d3168d68beb58a4c682f
MD5 5d561d3c03a762687334db9606c84090
BLAKE2b-256 56ce02c53c7a604f5845137e65fb33d5abae9bfb948146d7e73ff8ff2542a572

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page