Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gawel/chut
Small tool to interact with shell pipes
https://github.com/gawel/chut
Last synced: 2 months ago
JSON representation
Small tool to interact with shell pipes
- Host: GitHub
- URL: https://github.com/gawel/chut
- Owner: gawel
- Created: 2012-10-28T00:46:15.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2019-10-22T19:51:41.000Z (about 5 years ago)
- Last Synced: 2024-09-30T10:23:46.839Z (2 months ago)
- Language: Python
- Homepage: https://chut.readthedocs.org/en/latest/
- Size: 1.19 MB
- Stars: 16
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.rst
Awesome Lists containing this project
README
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+:
.. image:: 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 chutifyWrite a console script::
$ cat << EOF > myscript.py
from chut import *__version__ = '0.1'
@console_script
def mycmd(args):
"""Usage: %prog [options]Print all chut scripts found in
Options:
%options
"""
for filename in find('-name *.py') | grep('@console_script'):
print(filename)
EOFRun ``chutify`` in development mode::
$ ./chutify --devel
chmod +x bin/mycmdAnd 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/mycmdAlso 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 chutifyQuick 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 """
... if sh.ifconfig(args['']) | sh.grep('inet addr:'):
... return 1