Skip to main content

Small tool to interact with shell and pipes

Project description

Chut!

Chut is a small tool to help you to interact with shell pipes and commands.

Basically it will help to write some shell script in python

This is more like a toy than a real tool but… It may be useful sometimes.

It’s tested with and py3.5+:

https://secure.travis-ci.org/gawel/chut.png

Full documentation can be found here

Quick quick start

Get the chutify script:

$ wget https://raw.github.com/gawel/chut/master/docs/_static/binaries/chutify
$ chmod +x chutify

Write a console script:

$ cat << EOF > myscript.py
from chut import *

__version__ = '0.1'

@console_script
def mycmd(args):
    """Usage: %prog [options] <directory>

    Print all chut scripts found in <directory>

    Options:

    %options
    """
    for filename in find('-name *.py') | grep('@console_script'):
        print(filename)
EOF

Run chutify in development mode:

$ ./chutify --devel
chmod +x bin/mycmd

And use/debug the newly created script:

$ ./bin/mycmd -h

When your script is ready for production then generate the standalone version:

$ ./chutify
chmod +x dist/scripts/mycmd

Also have a look at the examples.

Installation

Using pip:

$ pip install chut

This will also install docopt and allow you to use the @console_script decorator.

Another option is to get chutify standalone version:

$ wget https://raw.github.com/gawel/chut/master/docs/_static/binaries/chutify
$ chmod +x chutify

Quick start

Import the shell:

>>> import chut as sh

Get a file content if it contains “Chut”:

>>> grep_chut = sh.cat('README.rst') | sh.grep('Chut')
>>> if grep_chut:
...     print(grep_chut | sh.head("-n1"))
Chut!

Redirect output to a file:

>>> ret = (grep_chut | sh.head("-n1")) > '/tmp/chut.txt'
>>> ret.succeeded
True
>>> print(sh.cat('/tmp/chut.txt'))
Chut!

Or to stdout:

>>> sh.cat('/tmp/chut.txt') > 1  # doctest: +SKIP
Chut!

Redirect stdout to stderr:

>>> sh.cat('/tmp/chut.txt') > 2  # doctest: +SKIP
Chut!

Run many command with a pool of processes:

>>> [ret.succeeded for ret in sh.ls.map(['.', ['-l', '/tmp']])]
[True, True]

Use docopt to write a console script. This script will take an iface as argument and return a code 1 if no address is found:

>>> @sh.console_script
... def got_inet_addr(args):
...     """Usage: got_inet_addr <iface>"""
...     if sh.ifconfig(args['<iface>']) | sh.grep('inet addr:'):
...         return 1

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

chut-0.18.tar.gz (514.7 kB view details)

Uploaded Source

Built Distribution

chut-0.18-py3-none-any.whl (21.1 kB view details)

Uploaded Python 3

File details

Details for the file chut-0.18.tar.gz.

File metadata

  • Download URL: chut-0.18.tar.gz
  • Upload date:
  • Size: 514.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for chut-0.18.tar.gz
Algorithm Hash digest
SHA256 30951bdb31054142563e03ac8ed386234e5b1b22751d74bda5c444b7f6f1f073
MD5 95e56a30cb949155f008a1065830c4e9
BLAKE2b-256 9f900b5b337dc7d627c9dc52127a8e7b5d2572b0ddc8ea87be457bbb80638c4d

See more details on using hashes here.

File details

Details for the file chut-0.18-py3-none-any.whl.

File metadata

  • Download URL: chut-0.18-py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.4.2 requests/2.20.1 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.3

File hashes

Hashes for chut-0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 33dd70bdda6d74c1e5b442e5008c46efdd8c477875c89e19e25c0f631d5d1ee3
MD5 b4c304eed39ad9124f95867064ca93e3
BLAKE2b-256 ffded6cc2651ef19061a89ece7c8116e674073fd4f7765cb9d433191bab1e785

See more details on using hashes here.

Supported by

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