How to use the bsddb3.db.DB_RDONLY 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 examachine / pisi / pisi / db / lockeddbshelve.py View on Github external
def close(self):
        if self.closed:
            return
        self.db.close()
        if self.flags & db.DB_RDONLY == 0:
            self.unlock()
        self.closed = True
github gramps-project / gramps / gramps / plugins / db / bsddb / summary.py View on Github external
LOG.warning("Error closing db environment for '%s': %s" %
                    (name, str(msg)))
        return "Unknown", bsddb_version, "Unknown"
    dbmap1 = dbshelve.DBShelf(env)
    fname = os.path.join(dirpath, META + ".db")
    try:
        dbmap1.open(fname, META, db.DB_HASH, db.DB_RDONLY)
    except:
        env.close()
        return "Unknown", bsddb_version, "Unknown"
    schema_version = dbmap1.get(b'version', default=None)
    dbmap1.close()
    dbmap2 = dbshelve.DBShelf(env)
    fname = os.path.join(dirpath, PERSON_TBL + ".db")
    try:
        dbmap2.open(fname, PERSON_TBL, db.DB_HASH, db.DB_RDONLY)
    except:
        env.close()
        return "Unknown", bsddb_version, schema_version
    count = len(dbmap2)
    dbmap2.close()
    env.close()
    return (count, bsddb_version, schema_version)
github gramps-project / gramps / gramps / plugins / db / bsddb / summary.py View on Github external
db.DB_INIT_LOG | db.DB_INIT_TXN
    try:
        env.open(dirpath, flags)
    except Exception as msg:
        LOG.warning("Error opening db environment for '%s': %s" %
                    (name, str(msg)))
        try:
            env.close()
        except Exception as msg:
            LOG.warning("Error closing db environment for '%s': %s" %
                    (name, str(msg)))
        return "Unknown", bsddb_version, "Unknown"
    dbmap1 = dbshelve.DBShelf(env)
    fname = os.path.join(dirpath, META + ".db")
    try:
        dbmap1.open(fname, META, db.DB_HASH, db.DB_RDONLY)
    except:
        env.close()
        return "Unknown", bsddb_version, "Unknown"
    schema_version = dbmap1.get(b'version', default=None)
    dbmap1.close()
    dbmap2 = dbshelve.DBShelf(env)
    fname = os.path.join(dirpath, PERSON_TBL + ".db")
    try:
        dbmap2.open(fname, PERSON_TBL, db.DB_HASH, db.DB_RDONLY)
    except:
        env.close()
        return "Unknown", bsddb_version, schema_version
    count = len(dbmap2)
    dbmap2.close()
    env.close()
    return (count, bsddb_version, schema_version)
github examachine / pisi / pisi / db / lockeddbshelve.py View on Github external
def open(self, filename, dbname, filetype, flags=db.DB_CREATE, mode=0644):
        self.filename = filename        
        self.closed = False
        if type(flags) == type(''):
            sflag = flags
            if sflag == 'r':
                flags = db.DB_RDONLY
            elif sflag == 'rw':
                flags = 0
            elif sflag == 'w':
                flags =  db.DB_CREATE
            elif sflag == 'c':
                flags =  db.DB_CREATE
            elif sflag == 'n':
                flags = db.DB_TRUNCATE | db.DB_CREATE
            else:
                raise Error, _("Flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags")
        self.flags = flags
        if self.flags & db.DB_RDONLY == 0:
            flags |= db.DB_AUTO_COMMIT # use txn subsystem in write mode
            self.lock()
        filename = os.path.realpath(filename) # we give absolute path due to dbenv
        #print 'opening', filename, filetype, flags, mode
github Pardus-Linux / pisi / pisi / db / lockeddbshelve.py View on Github external
if type(flags) == type(''):
            sflag = flags
            if sflag == 'r':
                flags = db.DB_RDONLY
            elif sflag == 'rw':
                flags = 0
            elif sflag == 'w':
                flags =  db.DB_CREATE
            elif sflag == 'c':
                flags =  db.DB_CREATE
            elif sflag == 'n':
                flags = db.DB_TRUNCATE | db.DB_CREATE
            else:
                raise Error, _("Flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags")
        self.flags = flags
        if self.flags & db.DB_RDONLY == 0:
            flags |= db.DB_AUTO_COMMIT # use txn subsystem in write mode
            self.lock()
        filename = os.path.realpath(filename) # we give absolute path due to dbenv
        #print 'opening', filename, filetype, flags, mode
        return self.db.open(filename, None, filetype, flags, mode)
github Phelimb / BIGSI / scripts / convert_v01_to_v03.py View on Github external
def convert_index(infile, config, num_samples):
    in_graph = db.DB()
    in_graph.set_cachesize(4,0)
    in_graph.open(infile+"/graph", flags=db.DB_RDONLY)

    # Create the kmer signature index
    storage=get_storage(config) 
    storage.set_integer(BLOOMFILTER_SIZE_KEY, config["m"])
    storage.set_integer(NUM_HASH_FUNCTS_KEY, config["h"])  
    BitMatrix.create(storage=storage,
        rows=get_rows(in_graph, config["m"]), num_rows=config["m"], num_cols=num_samples)
    in_graph.close()
github biopython / biopython / Bio / Mindy / BerkeleyDB.py View on Github external
def __init__(self, dbname, mode = "r"):
        if mode not in ("r", "rw"):
            raise TypeError("Unknown mode: %r" % (mode,))
        self.__need_flush = 0
        BaseDB.OpenDB.__init__(self, dbname, INDEX_TYPE)
        
        self.dbenv = None
        dbenv = db.DBEnv()
        envflags = db.DB_THREAD | db.DB_INIT_MPOOL
        dbenv.open(dbname, envflags)
        if mode == "r":
            self._dbopen_flags = db.DB_RDONLY
        else:
            self._dbopen_flags = 0

        self.primary_table = db.DB(dbenv)
        self.primary_table.open("key_%s" % (self.primary_namespace,),
                                None,
                                db.DB_BTREE, self._dbopen_flags, 0660)

        self.secondary_tables = {}
        self.dbenv = dbenv
github Pardus-Linux / pisi / pisi / db / lockeddbshelve.py View on Github external
def open(self, filename, dbname, filetype, flags=db.DB_CREATE, mode=0644):
        self.filename = filename
        self.closed = False
        if type(flags) == type(''):
            sflag = flags
            if sflag == 'r':
                flags = db.DB_RDONLY
            elif sflag == 'rw':
                flags = 0
            elif sflag == 'w':
                flags =  db.DB_CREATE
            elif sflag == 'c':
                flags =  db.DB_CREATE
            elif sflag == 'n':
                flags = db.DB_TRUNCATE | db.DB_CREATE
            else:
                raise Error, _("Flags should be one of 'r', 'w', 'c' or 'n' or use the bsddb.db.DB_* flags")
        self.flags = flags
        if self.flags & db.DB_RDONLY == 0:
            flags |= db.DB_AUTO_COMMIT # use txn subsystem in write mode
            self.lock()
        filename = os.path.realpath(filename) # we give absolute path due to dbenv
        #print 'opening', filename, filetype, flags, mode