[Yum] Calling yum from python

Chowdhury, Chandan Dutta (STSD) chandan-dutta.chowdhury at hp.com
Tue Aug 8 09:37:14 UTC 2006


Hello All,

I am trying to call yum from python. 
------------------------------------------------------------------------
---------
Following is the way I try to this [code-1]
------------------------------------------------------------------------
---------
#!/usr/bin/env python

import sys

sys.path.insert(0, "/usr/share/yum-cli")
import yummain
yummain.main("search bash".split())
------------------------------------------------------------------------
---------

But all I get is the usage message
------------------------------------------------------------------------
---------
You need to give some command

usage: yum [options] < update | install | info | remove | list |
    clean | provides | search | check-update | groupinstall |
    groupupdate | grouplist | groupinfo | groupremove |
    makecache | localinstall | erase | upgrade | whatprovides |
    localupdate | resolvedep | shell | deplist >

options:
  -h, --help            show this help message and exit
  -t, --tolerant        be tolerant of errors
  -C                    run entirely from cache, don't update cache
....
...
------------------------------------------------------------------------
---------
If I try this instead [code-2]
------------------------------------------------------------------------
---------
#!/usr/bin/env python

import sys

sys.path.insert(0, "/usr/share/yum-cli")
import yummain

sys.argv=sys.argv + "search bash".split()
yummain.main(sys.argv[1:])
------------------------------------------------------------------------
---------
It works without any problem

Code-1 works with 2.2.2 and not with 2.4.3 or 2.9.0 (I get the usage
message). I think yummain uses sys.argv instead of using the list
passed.
Code-1 works with all the version, but I don't want to set or change the
argv. 

The objective is to get the functionality of yum from python code

Thanks for any help

Regards
Chandan Dutta Chowdhury



More information about the Yum mailing list