The rpm base module provides the main starting point for accessing RPM from Python. For most usage, call the TransactionSet method to get a transaction set (rpmts).
import rpm ts = rpm.TransactionSet()
The transaction set will open the RPM database as needed, so in most cases, you do not need to explicitly open the database. The transaction set is the workhorse of RPM.
You can open another RPM database, such as one that holds all packages for a given Linux distribution, to provide packages used to solve dependencies. To do this, use the following code:
rpm.addMacro('_dbpath', '/path/to/alternate/database') solvets = rpm.TransactionSet() solvets.openDB() rpm.delMacro('_dbpath') # Open default database ts = rpm.TransactionSet()
This code gives you access to two RPM databases through two transaction sets (rpmts): ts is a transaction set associated with the default RPM database and solvets is a transaction set tied to an alternate database, which is very useful for resolving dependencies.
The rpm methods used here are:
|macro||Name of macro to add|
|value||Value for the macro|
|macro||Name of macro to delete|