Summary
After 0.5 released, I did so much exercise in my holidays, like hiking,
swimming, those less my hacking time, so ucltip development became very slowly recently,
which means 0.6 does not have too much changes!
New Feature: Pipeline
In subprocess, the way for doing pipeline is
>>> p1 = Popen(["dmesg"], stdout=PIPE) >>> = Popen(["grep", "hda"], stdin=p1.stdout, stdout=PIPE) >>>output = p2.communicate()[0] |
which is not convenience when you want to pipe many commands.
Pipe class provide similar interface as C library `libpipeline` (http://libpipeline.nongnu.org/)
that manipulating pipelines of subprocesses in a flexible and convenient way in C.
firstly, you need to create a Pipe instance
>>>pipe = ucltip.Pipe() |
and then add some command arguments as you want
>>>pipe.add('expr', 1, '+' 3) >>>pipe.add('sed', 's/4/5/', '--posix') |
finally run the process, wait it terminate and get its output
>>>pipe.wait() >>>pipe.stdout.read() 5 |
the first argument of Pipe.add function can be Cmd or SubCmd,
please remaind the usage of add function is changed in this case
Receive first arguments is instance of Cmd
>>>pipe = ucltip.Pipe() >>>pipe.add(Cmd('expr'), 1, '+', 3) >>>pipe.add(Cmd('sed'), 's/4/5', posix=True) >>>pipe.wait() >>>pipe.stdout.read() 5 |
Receive first arguments is instance of SubCmd
>>>apt_cache = ucltip.CmdDispatcher('apt-cache') >>>pipe = ucltip.Pipe() >>>pipe.add(apt_cache.search, 'vim-common') >>>pipe.add(Cmd('grep'), 'vim') >>>pipe.wait() >>>pipe.stdout.read() |
New Feature: Global Config
executing mode setting:
There are 3 type ofexecuting behavior of Cmd or CmdDispatcher, each are
- ‘process’: produce command string and execute (default)
- ‘list’, : only produce command arguments list
- ‘string’ : only produce command string
Example of list mode:
# produce command arguments only, same as dry_run >>>ucltip.global_config(execmod='list') >>>ucltip.Cmd('ls')(a=True) ['ls', '-a'] |
Example of string mode:
# produce command string only >>>ucltip.global_config(execmod='string') >>>ucltip.Cmd('ls')(a=True) 'ls -a' |
debug mode setting:
>>>import ucltip >>>ucltip.global_config(debug=True) >>>ucltip.Cmd('ls')() |
the debug message will be storaged in /var/log/syslog as the following
1896 Oct 4 21:36:53 host python: UCLTIP: Created a Cmd object bound 'ls'
1897 Oct 4 21:36:53 host python: UCLTIP: Trasform Kwargs:input:{}, result:[]
1898 Oct 4 21:36:53 host python: UCLTIP: Builded command string:['ls']
it includes
- command be bound
- the keyword arguments to command options transform input and output
- produced command line string
New Feature: Logging
The error message will also be logged in /var/log/syslog by default as the following
1899 Oct 4 21:42:53 host python: UCLTIP: Executed "ls --nonop" failed, Err Msg:ls: unrecognized option '--nonop'#012Try `ls - -help' for more information.
API Changes
Rename ‘interact’ parameter to ‘as_process’ of Cmd and CmdDispatcher.execute method for better understanding
>>>import ucltip >>>ls=ucltip.Cmd('ls') #old: >>>proc=ls(interact=True) #new: >>>proc=ls(as_process=True) |
How to install
Source Code released in http://pypi.python.org/pypi/ucltip, and
Debian unstable user can ‘python-ucltip’ package very soon.









