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+:
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
Metadata
Release files for chut 0.18
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| chut-0.18.tar.gz | 514.7 kB | Without provenance | Details for chut-0.18.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| chut-0.18-py3-none-any.whl | Python 3 | none | any | Details for chut-0.18-py3-none-any.whl |
Total release size: 535.8 kB
Release files / chut-0.18.tar.gz
| Download URL | chut-0.18.tar.gz |
|---|---|
| Size | 514.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
30951bdb31054142563e03ac8ed386234e5b1b22751d74bda5c444b7f6f1f073
|
|
BLAKE2b-256 checksum How to use checksums |
9f900b5b337dc7d627c9dc52127a8e7b5d2572b0ddc8ea87be457bbb80638c4d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / chut-0.18-py3-none-any.whl
| Download URL | chut-0.18-py3-none-any.whl |
|---|---|
| Size | 21.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
33dd70bdda6d74c1e5b442e5008c46efdd8c477875c89e19e25c0f631d5d1ee3
|
|
BLAKE2b-256 checksum How to use checksums |
ffded6cc2651ef19061a89ece7c8116e674073fd4f7765cb9d433191bab1e785
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Security for chut 0.18
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.