[Tutor] Trying to open RPM database with bsddb
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Wed Aug 20 13:06:24 EDT 2003
> I have since found the refered document. I can now create and re-open db
> files I have created. However, I cannot seem to open redhat rpm database
> files or freebsd pkgdb files. I keep getting an invalid argument error
> when using the syntax:
>
> >>> import anydbm
> >>> dbf = anydbm.open('pkgdb', 'r')
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python2.2/anydbm.py", line 86, in open
> return mod.open(file, flag, mode)
> File "/usr/lib/python2.2/dbhash.py", line 16, in open
> return bsddb.hashopen(file, flag, mode)
> bsddb.error: (22, 'Invalid argument')
>
> **Note I have also tried the above using bsdb abd dbhash with the same
> result.
>
> This appears that it may be a versioning issue between versions of
> berkley db but I am unsure since I have tried using the db_upgrade on
> (copies of) the files with the same results. If anyone has gotten this
> to work or has any additional info please let me know.
Hi Justin,
I was able to get something useful by using bsddb:
###
[dyoo at tesuque rpm]$ ls -l /var/lib/rpm/Packages
-rw-r--r-- 1 rpm rpm 22253568 Aug 11 14:24
/var/lib/rpm/Packages
[dyoo at tesuque rpm]$ file /var/lib/rpm/Packages
/var/lib/rpm/Packages: Berkeley DB (Hash, version 7, native byte-order)
###
The 'file' utility agrees with anydbm: the file format of the RPM database
is Berkeley DB.
It's possible that your Python distribution has an older version of bsddb
that isn't quite working. I know that bsddb was recently "overhauled" in
Python 2.3. (That is, completely deprecated and replaced by an
alternative implementation. *grin*)
You might want to see if you can open it using Python 2.3.
Alternatively, you may want to see if PyBSDDB can open it:
http://sourceforge.net/projects/pybsddb/
Here's what it looks like on my end:
###
[dyoo at tesuque rpm]$ /usr/local/bin/python
Python 2.3 (#1, Aug 1 2003, 17:14:57)
[GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bsddb
>>> packages = bsddb.hashopen('Packages')
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/local/lib/python2.3/bsddb/__init__.py", line 162, in hashopen
d.open(file, db.DB_HASH, flags, mode)
bsddb._db.DBAccessError: (13, 'Permission denied')
>>> packages = bsddb.hashopen('Packages', 'r')
>>>
>>> names = bsddb.hashopen('Name', 'r')
>>> names.next()
('cdparanoia', 'P\x04\x00\x00\x00\x00\x00\x00')
>>> names.next()
('libtool-libs', '\xbc\x02\x00\x00\x00\x00\x00\x00')
>>> names.next()
('crontabs', '\x0b\x00\x00\x00\x00\x00\x00\x00')
>>> names.next()
('man', 'J\x05\x00\x00\x00\x00\x00\x00')
>>> names.next()
('sysklogd', '\xef\x02\x00\x00\x00\x00\x00\x00')
>>> names.next()
('qt1x', '\x16\x00\x00\x00\x00\x00\x00\x00')
###
The bsddb package appears to be able to open the database file ok.
Anyway, I hope this helps get you started. Good luck!
More information about the Tutor
mailing list