Sep 28
YUM output parser (yum-parser.py)
As I needed to minimize yum’s output for a project I was working on, I thought it was just about changing the debugging level. But I found out yum’s debugging level could add information, but not minimize it. So wrote a small python script that does the job.
What I wanted to do, is replace yum’s output with a very simple progress bar showing only the different stages of a yum procedure (dependencies/download/install/remove/update).
The script is quite easy to use:
Usage: $ yum-parser.py (-u | --update) $ yum-parser.py (-i | --install) package_list $ yum-parser.py (-r | --remove) package_list $ yum-parser.py (-s | --search) 'regexp' $ yum-parser.py (-h | --help) package_list
For a reason I still ignore, when redirecting yum’s generic output to a file (e.g. yum -y install irssi 2>&1 > yumoutput), the “Downloading Packages” part doesn’t appear. To remedy this problem, I had to insert some threading to have a “patience bar” (i.e. back and forth [ = ]) while the downloads are processed.
You can find the source code here.
Let’s take a look at its output.
- Install, update or remove
- Search
When installing, updating or removing packages, yum-parser’s output will look something like below:
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -i vlc * Performing install of following package(s) and dependencies: ['vlc'] * Calculationg dependencies.This may take a few minutes. [ = ]
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -i vlc * Performing install of following package(s) and dependencies: ['vlc'] * Calculationg dependencies. Done. * This upgrade will install 49, update 0 and remove 0 packages * Downloading packages. This may take a few minutes. [ = ]
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -i vlc * Performing install of following package(s) and dependencies: ['vlc'] * Calculationg dependencies. Done. * This upgrade will install 49, update 0 and remove 0 packages * Downloading packages. Done. * Starting operations: [============================> 39% ]
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -i vlc * Performing install of following package(s) and dependencies: ['vlc'] * Calculationg dependencies. Done. * This upgrade will install 49, update 0 and remove 0 packages * Downloading packages. Done. * Starting operations: [==================================100%=====================================] Install Done.
Of course, when the requested package operation is not possible, the output is handeld as well. For example removing a package that is not installed:
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -r vlc * Performing remove of following package(s) and dependencies: ['vlc'] * Calculationg dependencies. Done. Requested package(s) is not installed.
Or try to install a package that does not exist:
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -i ghantoos * Performing install of following package(s) and dependencies: ['ghantoos'] * Calculationg dependencies. Done. Unknown package request.
I find this part quite useful. It was not hard to implement, it does the equivalent of a $ yum list | grep -e ‘regexp’. But it so much more user friendly than a yum search and plus it supports python regexp.
[ghantoos@raoul-centos5 ~]# sudo ./yum-parser.py -s 'irssi|vlc' * Searching for packages in pattern ['irssi|vlc'] irssi.i386 0.8.12-1.el5.rf installed vlc.i386 0.9.2-1.el5.rf rpmforge vlc-devel.i386 0.9.2-1.el5.rf rpmforge
I hope that you this can be useful to anyone.
Cheers,
Ghantoos
