Plumbum - Python Shell Combinators

jieforest發表於2012-05-28
[i=s] 本帖最後由 jieforest 於 2012-5-16 10:52 編輯

Ever wished the wrist-handiness of shellscripts be put into a real programming language? Say helloto Plumbum Shell Combinators. Plumbum (Latin for lead,which was used to create pipes back in the day) is a small yet feature-richlibrary for shell script-like programs in Python. The motto of the libraryis "Never write shell scripts again", and thus itattempts to mimic the shell syntax ("shellcombinators") where it makes sense, while keeping it all pythonicand cross-platform.


Apart from shell-like syntax and handyshortcuts, the library provides local and remote command execution (over SSH),local and remote file-system paths, easy working-directory and environmentmanipulation, and a programmatic Command-Line Interface (CLI) applicationtoolkit. Now let's see some code!


This is only a teaser; the fulldocumentation can be found at Read the Docs


[size=10.5pt]Basics

CODE:

>>> from plumbum import local, FG, BG
>>> from plumbum.cmd import ls, grep, wc, cat, head
>>> ls
LocalCommand()
>>> ls()
u'build.py\ndist\ndocs\nLICENSE\nplumbum\nREADME.rst\nsetup.py\ntests\ntodo.txt\n'

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-731270/,如需轉載,請註明出處,否則將追究法律責任。

相關文章