title: How do I compare Rpm versions in python
body: <p>I'm trying to find out how I can compare 2 lists of RPMS (Currently installed) and (Available in local repository) and see which RPMS are out of date. I've been tinkering with regex but there are so many different naming standards for RPMS that i can't get a good list to work with. I don't have the actual RPMS on my drive so i can't do rpm -qif.</p>
  
  <pre><code>pattern1 = re.compile(r'^([a-zA-Z0-9_\-\+]*)-([a-zA-Z0-9_\.]*)-([a-zA-Z0-9_\.]*)\.(.*)')
  for rpm in listOfRpms:
       packageInfo = pattern1.search(rpm[0]).groups()
       print packageInfo
  </code></pre>
  
  <p>This works for a vast majority but not all (2300 / 2400)</p>
  
  <pre><code>  yum-metadata-parser-1.1.2-2.el5
  ('yum-metadata-parser', '1.1.2', '2', 'el5') **What I need
  </code></pre>
  
  <p>But none these work for instance unless I break some others that worked before.. </p>
  
  <ul>
  <li>wvdial-1.54.0-3</li>
  <li>xdelta-1.1.3-20</li>
  <li>xdelta-1.1.3-20_2</li>
  <li>xmlsec1-1.2.6-3</li>
  <li>xmlsec1-1.2.6-3_2</li>
  <li>ypbind-1.17.2-13</li>
  <li>ypbind-1.17.2-8</li>
  <li>ypserv-2.13-14</li>
  <li>zip-2.3-27</li>
  <li>zlib-1.2.3-3</li>
  <li>zlib-1.2.3-3_2</li>
  <li>zsh-4.2.6-1</li>
  </ul>