There are a lot of lines of code in yum, and it can be somewhat intimidating at first glace. However a significant amount of effort has been made to make simple things easy, and the hard things not so hard. The start of any code using yum, will almost certainly have these four lines (and always the first and last one :).
1 #! /usr/bin/python -tt 2 3 import os 4 import sys 5 import yum
Those lines just tell python, you'd you'd like to be able to use the yum code, and some stuff for the OS. Next the first bit of real code, and something which is also in almost every piece of code using yum:
7 yb = yum.YumBase()
This creates a yum instance, that you can work with. Then one more piece, that is very useful:
9 yb.conf.cache = os.geteuid() != 0
This just tells the yum instance not to try and update any of it's data, as the caller of the script probably hasn't got the permissions to do so.( Read more...Collapse )