How to use the bsddb3.db.DB_BTREE function in bsddb3

To help you get started, we’ve selected a few bsddb3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tdhock / SegAnnDB / plotter / db.py View on Github external
if cls.RE_LEN:
                cls.db.set_re_len(cls.RE_LEN)
            cls.db.open(cls.filename, None, cls.DBTYPE,
                        bsddb3.db.DB_AUTO_COMMIT |
                        # bsddb3.db.DB_THREAD|
                        bsddb3.db.DB_CREATE)
            CLOSE_ON_EXIT.append(cls.db)

def rename_all(find, replace):
    for cls in DB_CLASSES:
        if all([k in cls.keys for k in find.keys()]):
            cls.rename_all(find, replace)

class Resource(object):
    __metaclass__ = DB
    DBTYPE = bsddb3.db.DB_BTREE
    RE_LEN = 0

    @classmethod
    def all(cls):
        return [cls(*tup).get() for tup in cls.db_key_tuples()]

    @classmethod
    def db_keys(cls):
        return cls.db.keys()

    @classmethod
    def db_key_tuples(cls):
        return [k.split(" ") for k in cls.db_keys()]

    def rename(self, **kwargs):
        """Read data for this key, delete that db entry, and save it under another key"""
github Tribler / tribler / Tribler / CacheDB / cachedb2.py View on Github external
def open_db(filename, db_dir='', filetype=db.DB_BTREE):
    if not db_dir:
        db_dir = home_dir
    dir = setDBPath(db_dir)
    path = os.path.join(dir, filename)
    try:
        d = dbshelve.open(path, filetype=filetype)
    except Exception, msg:
        print "cannot open dbshelve on", path, msg
        d = dbshelve.open(filename, filetype=filetype)
    return d
github terencehonles / mailman / Mailman / BDBMemberAdaptor.py View on Github external
def _setupDB(self, name):
        d = db.DB(self._env)
        openflags = db.DB_CREATE
        # db 4.1 requires that databases be opened in a transaction.  We'll
        # use auto commit, but only if that flag exists (i.e. we're using at
        # least db 4.1).
        try:
            openflags |= db.DB_AUTO_COMMIT
        except AttributeError:
            pass
        d.open(name, db.DB_BTREE, openflags)
        self._tables.append(d)
        return d
github RDFLib / rdflib / rdflib / backends / SleepyCat.py View on Github external
envflags = db.DB_INIT_MPOOL | db.DB_INIT_CDB | db.DB_THREAD
        try:
            if not exists(homeDir):
                mkdir(homeDir)
        except Exception, e:
            print e
        self.env = env = db.DBEnv()
        env.set_cachesize(0, 1024*1024*50)
        #env.set_lg_max(1024*1024)
        env.set_flags(envsetflags, 1)
        env.open(homeDir, envflags | db.DB_CREATE)

        self.__open = 1
        
        dbname = None
        dbtype = db.DB_BTREE
        dbopenflags = db.DB_THREAD
        
        dbmode = 0660
        dbsetflags   = 0

        # create and open the DBs
        self.__contexts = db.DB(env)
        self.__contexts.set_flags(dbsetflags)
        self.__contexts.open("contexts", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
        self.__spo = db.DB(env)
        self.__spo.set_flags(dbsetflags)
        self.__spo.open("spo", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)

        self.__pos = db.DB(env)
        self.__pos.set_flags(dbsetflags)
        self.__pos.open("pos", dbname, dbtype, dbopenflags|db.DB_CREATE, dbmode)
github RDFLib / rdflib / rdflib / plugins / sleepycat.py View on Github external
def open(self, path, create=True):
        if not has_bsddb:
            return NO_STORE
        homeDir = path

        if self.__identifier is None:
            self.__identifier = URIRef(pathname2url(abspath(homeDir)))

        db_env = self._init_db_environment(homeDir, create)
        if db_env == NO_STORE:
            return NO_STORE
        self.db_env = db_env
        self.__open = True

        dbname = None
        dbtype = db.DB_BTREE
        # auto-commit ensures that the open-call commits when transactions
        # are enabled

        dbopenflags = DBOPENFLAGS
        if self.transaction_aware is True:
            dbopenflags |= db.DB_AUTO_COMMIT

        if create:
            dbopenflags |= db.DB_CREATE

        dbmode = 0o660
        dbsetflags = 0

        # create and open the DBs
        self.__indicies = [None, ] * 3
        self.__indicies_info = [None, ] * 3
github Pardus-Linux / pisi / pisi / db / lockeddbshelve.py View on Github external
def __init__(self, dbname, mode=0644,
                 filetype=db.DB_BTREE, dbenv = None):
        if dbenv == None:
            dbenv = ctx.dbenv
        shelve.DBShelf.__init__(self, dbenv)
        filename = pisi.util.join_path(pisi.context.config.db_dir(), dbname + '.bdb')
        if dbenv and os.access(os.path.dirname(filename), os.W_OK):
            flags = 'w'
        elif os.access(filename, os.R_OK):
            flags = 'r'
        else:
            raise Error(_('Cannot attain read or write access to database %s') % dbname)
        self.open(filename, dbname, filetype, flags, mode)
github coleifer / kvkit / kvkit / backends / berkeleydb.py View on Github external
page_size=None, lorder=None):

        self.filename = filename
        flags = bsddb3._checkflag(flag, filename)
        env = bsddb3._openDBEnv(cache_size)
        db = bsddb3.db.DB(env)
        if page_size is not None:
            db.set_pagesize(page_size)
        if lorder is not None:
            db.set_lorder(lorder)
        db.set_flags(btflags)
        if minkeypage is not None:
            db.set_bt_minkey(minkeypage)
        if maxkeypage is not None:
            db.set_bt_maxkey(maxkeypage)
        db.open(self.filename, bsddb3.db.DB_BTREE, flags, mode)
        super(BerkeleyDB, self).__init__(db)
github cheshire3 / cheshire3 / cheshire3 / indexStore.py View on Github external
def _openMetadata(self, session):
        if self.metadataCxn is not None:
            return self.metadataCxn
        else:
            mp = self.get_path(session, 'metadataPath')
            if not mp:
                dfp = self.get_path(session, 'defaultPath')
                mp = os.path.join(dfp, 'metadata.bdb')

            if not os.path.exists(mp):
                oxn = bdb.db.DB()
                oxn.open(mp, dbtype=bdb.db.DB_BTREE,
                         flags=bdb.db.DB_CREATE, mode=0660)
                oxn.close()

            cxn = bdb.db.DB()
            if session.environment == "apache":
                cxn.open(mp, flags=bdb.db.DB_NOMMAP)
            else:
                cxn.open(mp)
            self.metadataCxn = cxn
            return cxn