thomas: utils/admin convert-gdbm-dbload,NONE,1.1

cvs at kolab.org cvs at kolab.org
Wed May 2 18:04:27 CEST 2007


Author: thomas

Update of /kolabrepository/utils/admin
In directory doto:/tmp/cvs-serv4596

Added Files:
	convert-gdbm-dbload 
Log Message:
Python script to convert pfbcache.db after gdbm->db4 migration.


--- NEW FILE: convert-gdbm-dbload ---
#!/usr/bin/env python
# $Id: convert-gdbm-dbload,v 1.1 2007/05/02 16:04:25 thomas Exp $
#
# Copyright (C) 2007 by Intevation GmbH
# Author(s):
# Thomas Arendsen Hein <thomas at intevation.de>
#
# This program is free software under the GNU GPL (>=v2)

"""convert-gdbm-dbload

Usage:
  convert-gdbm-dbload pfbcache.db-gdbm | db_load pfbcache.db-db4

Read gdbm database and dump in a format suitable for db_load.
db_load is part of Berkeley DB.

Requires python (tested with version 2.3) and the python-gdbm module.
"""

__version__ = "$Revision: 1.1 $"

import sys
import binascii
import gdbm


def error(msg):
    sys.stderr.write('%s\n' % (msg,))
    sys.exit(1)


def main(gdbmfile):
    """Read gdbm database and dump in a format suitable for db_load."""
    try:
        db = gdbm.open(gdbmfile)
    except gdbm.error, inst:
        if len(inst.args) == 2:
            error('Error opening %s: %s' % (gdbmfile, inst[1]))
        else:
            error('Error opening %s: %s' % (gdbmfile, inst))

    sys.stdout.write(
        "VERSION=3\n"
        "format=bytevalue\n"
        "type=btree\n"
        "db_pagesize=4096\n"
        "HEADER=END\n"
    )

    k = db.firstkey()
    while k != None:
        sys.stdout.write(" %s\n %s\n"
                         % (binascii.hexlify(k), binascii.hexlify(db[k])))
        k = db.nextkey(k)
    db.close()

    sys.stdout.write("DATA=END\n")

if __name__ == "__main__":
    if len(sys.argv) != 2:
        error('Usage: %s pfbcache.db-gdbm | db_load pfbcache.db-db4'
              % sys.argv[0])
    else:
        main(sys.argv[1])






More information about the commits mailing list