James Antill (illiterat) wrote,

Programming with Yum in 5 minutes, or so

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 )
Tags: example, python, yum

rahulsundaram

August 30 2008, 16:04:13 UTC 5 years ago

  • New comment

Excellent

Very nice introduction.

Error

default userpic

Your reply will be screened

Your IP address will be recorded