Product SiteDocumentation Site

Chapter 16. Programming RPM with Python

16.1. Setting Up a Python Development Environment
16.1.1. Installing the base Python packages
16.1.2. Using Python for graphics
16.2. The Python API Hierarchy
16.3. Programming with the RPM Database
16.3.1. Accessing the RPM database
16.3.2. Querying the RPM database
16.3.3. Examining the package header
16.3.4. Querying for specific packages
16.3.5. Printing information on packages
16.3.6. Refining queries
16.4. Reading Package Files
16.4.1. Reading headers from package files
16.4.2. Setting the verification flags
16.5. Dependency Comparisons
16.6. Installing and Upgrading Packages
16.6.1. Building up the transaction set
16.6.2. Transaction elements
16.6.3. Checking and reordering the transaction elements
16.6.4. Running the transaction
16.7. Where to Go from Here
16.8. Summary
This chapter covers:

Setting Up a Python Development Environment

Setting up a Python development environment is much the same as setting up a C programming environment. You need to install a set of packages for general Python development, install a package that provides the Python API to the RPM system, and choose a program for editing your Python scripts.
Cross Reference
Chapter 26, Linux Text Editors and Development Tools covers Linux text editors and development tools.
If you want to make a graphical user interface in your Python programs, you need to install a separate Python package.

Installing the base Python packages

The base Python package needed for developing applications is python. For RPM usage, you should install Python 2.2, not Python 1.5. That’s because the RPM bindings for Python are moving to support only 2.2 and higher releases.
The Python package for RPM access is rpm-python. Install these as you would any other packages.
Cross Reference
Chapter 3, Using RPM covers installing packages.

Using Python for graphics

Python supports a number of different toolkits for creating graphical user interfaces. You need one of these toolkits if you want to create Python applications that sport a user interface instead of command-line tools. Among the most popular toolkits are PyGKT, PyQt, and Tkinter.
*PyGTK is a binding between Python and the GTK+ toolkit used by the GNOME desktop, one of two main desktop environments for Linux. (KDE is the other main desktop environment.) The Red Hat redhat-config-packages program uses PyGTK and sports a very good-looking user interface.
PyGTK provides full access to the GTK+ widgets such as menus, dialog windows, and buttons. Install the pygtk2 module for PyGTK. For more on PyGTK, see www.daa.com.au/~james/pygtk/.
*PyQt connects Python scripts to the Qt C++ user interface toolkit. Qt forms the base library used by the KDE desktop environment and KDE applications. As with PyGTK, PyQt allows you to access the rich widget set provided by the library.
Install the PyQt package for PyQt. For more on PyQt, see www.riverbankcomputing.co.uk/pyqt/.
*Tkinter is considered a standard part of Python and is based on the Tk (pronounced teekay) toolkit from the Tcl scripting language. The main advantages of Tkinter are that it is considered part of Python, meaning users are more likely to have it, and Tkinter works on multiple platforms, including Windows.
The main drawback of Tkinter is that the widget sets are not as rich as PyQt or PyGTK. For more on Tkinter, see www.python.org/topics/tkinter/.
After you’ve set up your environment and installed all the necessary packages, the next step is to start working with the Python API for RPM.