<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>rpm: Rpmdb Class Reference</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> </head><body> <!-- Generated by Doxygen 1.4.7 --> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="modules.html"><span>Modules</span></a></li> <li id="current"><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="files.html"><span>Files</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> </ul></div> <div class="tabs"> <ul> <li><a href="annotated.html"><span>Data Structures</span></a></li> <li><a href="functions.html"><span>Data Fields</span></a></li> </ul></div> <h1>Rpmdb Class Reference<br> <small> [<a class="el" href="group__python.html">PYTHON API.</a>]</small> </h1><!-- doxytag: class="Rpmdb" -->A python rpmdb object represents an RPM database. <a href="#_details">More...</a> <p> <table border="0" cellpadding="0" cellspacing="0"> <tr><td></td></tr> </table> <hr><a name="_details"></a><h2>Detailed Description</h2> A python rpmdb object represents an RPM database. <p> Instances of the rpmdb object provide access to the records of a RPM database. The records are accessed by index number. To retrieve the header data in the RPM database, the rpmdb object is subscripted as you would access members of a list.<p> The rpmdb class contains the following methods:<p> <ul> <li>firstkey() Returns the index of the first record in the database. <dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000024">Deprecated:</a></b></dt><dd>Use mi = ts.dbMatch() (or <a class="el" href="softmagic_8c.html#d68b27ad2f9373b2f0e974e3f8dbf314">db.match()</a>) instead.</dd></dl> </li><li>nextkey(index) Returns the index of the next record after "index" in the database. <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>index</em> </td><td>current rpmdb location </td></tr> </table> </dl> <dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000024">Deprecated:</a></b></dt><dd>Use hdr = <a class="el" href="llex_8c.html#63a4975e63fa906cd2432d0e7b65d304">mi.next()</a> instead.</dd></dl> </li><li>findbyfile(file) Returns a list of the indexes to records that own file "file". <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>file</em> </td><td>absolute path to file </td></tr> </table> </dl> <dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000024">Deprecated:</a></b></dt><dd>Use mi = ts.dbMatch('basename') instead.</dd></dl> </li><li>findbyname(name) Returns a list of the indexes to records for packages named "name". <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>name</em> </td><td>package name </td></tr> </table> </dl> <dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000024">Deprecated:</a></b></dt><dd>Use mi = ts.dbMatch('name') instead.</dd></dl> </li><li>findbyprovides(dep) Returns a list of the indexes to records for packages that provide "dep". <dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>dep</em> </td><td>provided dependency string </td></tr> </table> </dl> <dl compact><dt><b><a class="el" href="deprecated.html#_deprecated000024">Deprecated:</a></b></dt><dd>Use mi = ts.dbMmatch('providename') instead.</dd></dl> To obtain a db object explicitly, the opendb function in the rpm module can be called. The opendb function takes two optional arguments. The first optional argument is a boolean flag that specifies if the database is to be opened for read/write access or read-only access. The second argument specifies an alternate root directory for RPM to use.</li></ul> <p> Note that in most cases, one is interested in querying the default database in /var/lib/rpm and an rpm.mi match iterator derived from an implicit open of the database from an rpm.ts transaction set object: <div class="fragment"><pre class="fragment"> <span class="keyword">import</span> rpm ts = rpm.TransactionSet() mi = ts.dbMatch() ... </pre></div> is simpler than explicitly opening a database object: <div class="fragment"><pre class="fragment"> <span class="keyword">import</span> rpm db = rpm.opendb() mi = db.match() </pre></div><p> An example of opening a database and retrieving the first header in the database, then printing the name of the package that the header represents: <div class="fragment"><pre class="fragment"> <span class="keyword">import</span> rpm db = rpm.opendb() mi = db.match() <span class="keywordflow">if</span> mi: h = mi.next() <span class="keywordflow">if</span> h: print h['<a class="code" href="structname.html">name</a>'] </pre></div><p> To print all of the packages in the database that match a package name, the code will look like this: <div class="fragment"><pre class="fragment"> <span class="keyword">import</span> rpm db = rpm.opendb() mi = db.match('<a class="code" href="structname.html">name</a>', <span class="stringliteral">"foo"</span>) <span class="keywordflow">while</span> mi: h = mi.next() <span class="keywordflow">if</span> not h: <span class="keywordflow">break</span> print <span class="stringliteral">"%s-%s-%s"</span> % (h['<a class="code" href="structname.html">name</a>'], h['version'], h['release']) </pre></div> <p> <hr>The documentation for this class was generated from the following file:<ul> <li>python/<a class="el" href="rpmdb-py_8c-source.html">rpmdb-py.c</a></ul> <hr size="1"><address style="align: right;"><small>Generated on 1 Oct 2013 for rpm by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.7 </small></address> </body> </html>