Re: rpmUtils cvs repository
Ville Skyttä <[email protected]> Mon, 22 Mar 2004 22:30:51 +0200
| Newsgroups | gmane.linux.redhat.rpm.python |
|---|---|
| Message-ID | <[email protected]> |
On Mon, 2004-03-22 at 08:54, seth vidal wrote: > I setup a cvs repo for the rpmUtils module I've been slowly assembling. Cool. Here's a snippet I've had around for some time: a raw implementation of rpm2cpio in Python, feel free to include if you find it useful. Dunno if miscutils is the best place though. (Yes, error checking / closing the input fd on errors could be improved a bit ;) _______________________________________________ Rpm-python-list mailing list Rpm-python-list-cunTk1MwBs9zPNxIf5reH/[email protected] https://lists.dulug.duke.edu/mailman/listinfo/rpm-python-list
miscutils-rpm2cpio.patch
(text/x-patch, 1.3 KB)
Index: miscutils.py
===================================================================
RCS file: /cvsroot/rpmutils/cvs-root/rpmUtils/miscutils.py,v
retrieving revision 1.2
diff -a -u -r1.2 miscutils.py
--- miscutils.py 20 Mar 2004 19:08:33 -0000 1.2
+++ miscutils.py 22 Mar 2004 20:29:06 -0000
@@ -15,7 +15,11 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Copyright 2003 Duke University
+import gzip
+import os
import rpm
+import sys
+import rpmUtils.transaction
import types
def rpmOutToStr(arg):
@@ -217,3 +221,24 @@
u.append(x)
return u
+
+def rpm2cpio(fdno, out=sys.stdout, bufsize=2048):
+ """Performs roughly the equivalent of rpm2cpio(8).
+ Reads the package from fdno, and dumps the cpio payload to out,
+ using bufsize as the buffer size."""
+ ts = rpmUtils.transaction.initReadOnlyTransaction()
+ hdr = ts.hdrFromFdno(fdno)
+ del ts
+ compr = hdr[rpm.RPMTAG_PAYLOADCOMPRESSOR] or 'gzip'
+ #if compr == 'bzip2':
+ # TODO: someone implement me!
+ #el
+ if compr != 'gzip':
+ raise rpmUtils.RpmUtilsError, \
+ 'Unsupported payload compressor: "%s"' % compr
+ f = gzip.GzipFile(None, 'rb', None, os.fdopen(fdno, 'rb', bufsize))
+ while 1:
+ tmp = f.read(bufsize)
+ if tmp == "": break
+ out.write(tmp)
+ f.close()