rpm5 & ts.hdrFromFdno from .hdr file
Elan Ruusamäe
glen at pld-linux.org
Sat May 18 23:12:31 CEST 2013
On 05/18/2013 08:58 PM, Jeffrey Johnson wrote:
>> >header is extracted from this repodata info:
>> >
>> > <rpm:header-range start="368" end="7947"/>
>> >
>> >perhaps those offsets are incorrect?
>> >
> Heh: offsets being different.
so, i found rpm5 has the offsets stored in headers already, and those
give the same offsets out, which seem to be correct (compared to what
rpm/yum on fedora does)
# ./hw5.py blockdev-2.22.2-4.i686.rpm
st: 368, end: 7947
START: 368, END: 7947, SIZE: 7579
Wrote: blockdev-2.22.2-4.i686.rpm.rpm5.hdr
# md5sum *.hdr
ce84368ce713e81ad50214c9021f46d3 blockdev-2.22.2-4.i686.rpm.hdr
ce84368ce713e81ad50214c9021f46d3 blockdev-2.22.2-4.i686.rpm.rpm5.hdr
altho all the files used in the tests are in this [1] archive, showing
the .py here as well:
[1] http://carme.pld-linux.org/~glen/rpm5-hdr.tar
# cat hw5.py
#!/usr/bin/python
import os, sys, rpm
def get_hdr(rpm_file):
ts = rpm.ts()
fdno = os.open(rpm_file, os.O_RDONLY)
hdr = ts.hdrFromFdno(fdno)
os.close(fdno)
return hdr
def _get_header_byte_range(localpath):
hdr = get_hdr(localpath)
print "st: %s, end: %s" % (hdr[1211], hdr[1212])
q = hdr.sprintf('%{HEADERSTARTOFF} %{HEADERENDOFF}')
(start, end) = q.split(' ')
return (int(start), int(end))
fn = sys.argv[1]
(start,end) = _get_header_byte_range(fn)
size = end-start
print "START: %d, END: %d, SIZE: %d" % (start,end,size)
f = open(fn, 'r')
f.seek(start)
h = f.read(size)
f.close()
hfn = '%s.rpm5.hdr' % fn
f = open(hfn, 'w')
f.write(h)
f.close()
print "Wrote: %s" % hfn
--
glen
More information about the pld-devel-en
mailing list