Sophie

Sophie

distrib > CentOS > 5 > x86_64 > by-pkgid > 67e32647b06c0323bf90c6b54a6438d1 > files > 34

rpm-apidocs-4.4.2.3-34.el5.x86_64.rpm

<!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: Rpmhdr 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&nbsp;Page</span></a></li>
    <li><a href="modules.html"><span>Modules</span></a></li>
    <li id="current"><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="files.html"><span>Files</span></a></li>
    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>
  </ul></div>
<div class="tabs">
  <ul>
    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>
    <li><a href="functions.html"><span>Data&nbsp;Fields</span></a></li>
  </ul></div>
<h1>Rpmhdr Class Reference<br>
<small>
[<a class="el" href="group__python.html">PYTHON API.</a>]</small>
</h1><!-- doxytag: class="Rpmhdr" -->A python header object represents an RPM package header.  
<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 header object represents an RPM package header. 
<p>
All RPM packages have headers that provide metadata for the package. Header objects can be returned by database queries or loaded from a binary package on disk.<p>
The ts.hdrFromFdno() function returns the package header from a package on disk, verifying package signatures and digests of the package while reading.<p>
Note: The older method rpm.headerFromPackage() which has been replaced by ts.hdrFromFdno() used to return a (hdr, isSource) tuple.<p>
If you need to distinguish source/binary headers, do: <div class="fragment"><pre class="fragment">        <span class="keyword">import</span> os, rpm

        ts = rpm.TranssactionSet()
        fdno = os.open(<span class="stringliteral">"/tmp/foo-1.0-1.i386.rpm"</span>, os.O_RDONLY)
        hdr = ts.hdrFromFdno(fdno)
        os.close(fdno)
        <span class="keywordflow">if</span> hdr[rpm.RPMTAG_SOURCEPACKAGE]:
           print <span class="stringliteral">"header is from a source package"</span>
        <span class="keywordflow">else</span>:
           print <span class="stringliteral">"header is from a binary package"</span>
</pre></div><p>
The Python interface to the header data is quite elegant. It presents the data in a dictionary form. We'll take the header we just loaded and access the data within it: <div class="fragment"><pre class="fragment">        print hdr[rpm.RPMTAG_NAME]
        print hdr[rpm.RPMTAG_VERSION]
        print hdr[rpm.RPMTAG_RELEASE]
</pre></div> in the case of our "foo-1.0-1.i386.rpm" package, this code would output: <div class="fragment"><pre class="fragment">  	foo
  	1.0
  	1
</pre></div><p>
You make also access the header data by string name: <div class="fragment"><pre class="fragment">        print hdr['<a class="code" href="structname.html">name</a>']
        print hdr['version']
        print hdr['release']
</pre></div><p>
This method of access is a teensy bit slower because the name must be translated into the tag number dynamically. You also must make sure the strings in header lookups don't get translated, or the lookups will fail. 
<p>
<hr>The documentation for this class was generated from the following file:<ul>
<li>python/<a class="el" href="header-py_8c-source.html">header-py.c</a></ul>
<hr size="1"><address style="align: right;"><small>Generated on 1 Oct 2013 for rpm by&nbsp;
<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>