4

I'm writing a tool to verify RPMs in Python and print out the actual diffs in the files that changed.

I can fetch the RPMs from the ftp server with ftplib. I was thinking of saving the rpm in /tmp and using subprocess module to run

rpm2cpio myrpmfile.rpm | cpio -idmv

to get the files in the RPM so that I can diff the files. Afterwards, I'll delete the temp files.

It seems a bit hacky, so is this the best approach, or is there a more elegant solution with Python?

jh314
  • 27,144
  • 16
  • 62
  • 82

1 Answers1

0

You can probably use one of the python libarchive interfaces, which support cpio files. The main ones seem to be libarchive and libarchive-c. RPM also comes with a python interface, but it appears to be considerably more work to get it to do what you want to do.

TheBlackCat
  • 9,791
  • 3
  • 24
  • 31
  • This seems to me more of a comment than an answer, particularly since the core of it is link only. – Two-Bit Alchemist Mar 24 '15 at 19:01
  • 1
    This still requires to first extract the cpio archive from the rpm archive. That is quite simple: [Here is the spec](http://www.rpm.org/max-rpm/s1-rpm-file-format-rpm-file-format.html) and, maybe useful as a starting point, [here a hack'ish implementation I once wrote for personal use](https://github.com/phillipberndt/scripts/blob/5f006095c7bc9628f0811844c957bedbacd2a6ce/unpack/unpack#L366). – Phillip Mar 24 '15 at 19:02