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 py2.6+ and py3.2+:

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

Full documentation can be found here

Installation

Using pip:

$ pip install chut

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

Quick start

Import the shell:

>>> import chut as sh

Get a file content if he 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!

Use docopt to write a console script. This script will take an iface as argument and return a code 1 if no addresses are 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

>>> if __name__ == '__main__':
...     got_inet_addr()

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.5.tar.gz (12.7 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: chut-0.5.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for chut-0.5.tar.gz
Algorithm Hash digest
SHA256 1cd3dbebb68404190e741a67d20542d47d4e1d067874303bf00acee08ca8b2c0
MD5 3d415b6a425c355fd0de3a4672ce8871
BLAKE2b-256 9985bbd527d212dad5557caf0baefa89d7aaad9a99e0b188f9a237d05ad6709b

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