當前位置: 首頁>>代碼示例>>Python>>正文


Python plyvel.DB屬性代碼示例

本文整理匯總了Python中plyvel.DB屬性的典型用法代碼示例。如果您正苦於以下問題:Python plyvel.DB屬性的具體用法?Python plyvel.DB怎麽用?Python plyvel.DB使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在plyvel的用法示例。


在下文中一共展示了plyvel.DB屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def __init__(self, name, truncate=False, bloom_filter_bits=0):
        if truncate:
            try:
                shutil.rmtree(name)
            except:
                pass

        self.db = None
        self._compact_glet = None

        self.db = plyvel.DB(
            name,
            create_if_missing=True,
            bloom_filter_bits=bloom_filter_bits
        )
        self._read_metadata()

        self.compact_interval = int(os.environ.get('MM_TABLE_COMPACT_INTERVAL', 3600 * 6))
        self.compact_delay = int(os.environ.get('MM_TABLE_COMPACT_DELAY', 3600))
        self._compact_glet = gevent.spawn(self._compact_loop) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:22,代碼來源:table.py

示例2: __init__

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def __init__(self, name, epsize, truncate=False,
                 bloom_filter_bits=10, write_buffer_size=(4 << 20)):
        if truncate:
            try:
                shutil.rmtree(name)
            except:
                pass

        self.db = plyvel.DB(
            name,
            create_if_missing=True,
            write_buffer_size=write_buffer_size,
            bloom_filter_bits=bloom_filter_bits
        )
        self.epsize = epsize
        self.max_endpoint = (1 << epsize)-1

        self.num_endpoints = 0
        self.num_segments = 0 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:21,代碼來源:st.py

示例3: __init__

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def __init__(self, db_dir=None):
        self.db_dir = os.path.join(config.user.data_dir, config.dev.db_name)
        if db_dir:
            self.db_dir = db_dir
        logger.info('DB path: %s', self.db_dir)

        os.makedirs(self.db_dir, exist_ok=True)

        try:
            self.db = plyvel.DB(self.db_dir, max_open_files=1000, lru_cache_size=5 * 1024)
        except Exception:
            self.db = plyvel.DB(self.db_dir,
                                max_open_files=1000,
                                lru_cache_size=5 * 1024,
                                create_if_missing=True,
                                compression='snappy')
            self.db.put(b'state_version', str(1).encode()) 
開發者ID:theQRL,項目名稱:QRL,代碼行數:19,代碼來源:db.py

示例4: __init__

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def __init__(self, engine, dbname):
        self.engine = engine
        self.dbname = dbname
        self.DB = None
        self.iterator = None
        self.simulating = False
        self.simulation_owner = ''
        self.salt = None
        self.req_count = 0
        self.log = dict()
        try:
            db_location = os.path.join(self.engine.working_dir, self.dbname)
            DB = plyvel.DB(db_location, create_if_missing=True)
            self.DB = DB.prefixed_db(custom.version.encode())
            self.iterator = self.DB.iterator
        except Exception as e:
            tools.log(e)
            sys.stderr.write('Database connection cannot be established!\n') 
開發者ID:halilozercan,項目名稱:halocoin,代碼行數:20,代碼來源:database.py

示例5: upgrade_v3

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def upgrade_v3(config: "Config") -> None:
    """Converts the given legacy config into the new config + LevelDB storage scheme."""

    bot_config: "BotConfig" = config["bot"]

    if "default_prefix" not in bot_config:
        log.info("Renaming 'prefix' key to 'default_prefix' in bot config section")
        bot_config["default_prefix"] = bot_config["prefix"]
        del bot_config["prefix"]

    if "db_path" not in bot_config:
        log.info("Adding default database path 'main.db' to bot config section")
        bot_config["db_path"] = "main.db"

    async with AsyncDB(
        plyvel.DB(config["bot"]["db_path"], create_if_missing=True)
    ) as db:
        await _migrate_antibot(config, db)
        await _migrate_snippets(config, db)
        await _migrate_stats(config, db)
        await _migrate_stickers(config, db) 
開發者ID:kdrag0n,項目名稱:pyrobud,代碼行數:23,代碼來源:config_db_migrator.py

示例6: _load_validation_data

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def _load_validation_data(validation_leveldb, width, height):
    """
    Loads all of our validation data from our leveldb database, producing unrolled numpy input
    vectors ready to test along with their correct, expected target values.
    """

    print "\tLoading validation data..."
    input_vectors = []
    expected_targets = []

    db = plyvel.DB(validation_leveldb)
    for key, value in db:
        datum = Datum()
        datum.ParseFromString(value)

        data = np.fromstring(datum.data, dtype=np.uint8)
        data = np.reshape(data, (3, height, width))
        # Move the color channel to the end to match what Caffe wants.
        data = np.swapaxes(data, 0, 2) # Swap channel with width.
        data = np.swapaxes(data, 0, 1) # Swap width with height, to yield final h x w x channel.

        input_vectors.append(data)
        expected_targets.append(datum.label)

    db.close()

    print "\t\tValidation data has %d images" % len(input_vectors)

    return {
        "input_vectors": np.asarray(input_vectors),
        "expected_targets": np.asarray(expected_targets)
    } 
開發者ID:BradNeuberg,項目名稱:cloudless,代碼行數:34,代碼來源:predict.py

示例7: __init__

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def __init__(self, name, create_if_missing=True):
        LOG.debug('New table: %s %s', name, create_if_missing)

        self.name = name
        self.last_used = None
        self.refs = []

        if not create_if_missing and not os.path.exists(name):
            raise TableNotFound('Table does not exists')

        try:
            self.db = plyvel.DB(
                name,
                create_if_missing=create_if_missing
            )

        except plyvel.Error as e:
            if not create_if_missing:
                raise TableNotFound(str(e))
            raise

        self.max_counter = None
        try:
            self.max_counter = self.db.get(TABLE_MAX_COUNTER_KEY)

        except KeyError:
            pass

        if self.max_counter is None:
            LOG.warning(
                'MAX_ID key not found in %s',
                self.name
            )
            self.max_counter = -1

        else:
            self.max_counter = int(self.max_counter, 16)

        LOG.debug('Table %s - max id: %d', self.name, self.max_counter) 
開發者ID:PaloAltoNetworks,項目名稱:minemeld-core,代碼行數:41,代碼來源:storage.py

示例8: __init__

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def __init__(self, db: plyvel.DB, sync: bool):
        self._batch = self._new_batch(db, sync) 
開發者ID:icon-project,項目名稱:loopchain,代碼行數:4,代碼來源:key_value_store_plyvel.py

示例9: _new_batch

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def _new_batch(self, db: plyvel.DB, sync: bool):
        return db.write_batch(sync=sync) 
開發者ID:icon-project,項目名稱:loopchain,代碼行數:4,代碼來源:key_value_store_plyvel.py

示例10: _new_db

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def _new_db(self, path, **kwargs) -> plyvel.DB:
        return plyvel.DB(path, **kwargs) 
開發者ID:icon-project,項目名稱:loopchain,代碼行數:4,代碼來源:key_value_store_plyvel.py

示例11: open

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def open(self):
        import plyvel
        self.db = plyvel.DB(self.path, create_if_missing=True) 
開發者ID:dragondjf,項目名稱:QMusic,代碼行數:5,代碼來源:leveldict.py

示例12: get_ldb_pairs

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def get_ldb_pairs(ldb_path, prefix=''):
    """Open a LevelDB at given path and return a list of all key/value pairs, optionally
    filtered by a prefix string. Key and value are kept as byte strings """

    try:
        import plyvel
    except ImportError:
        log.warning(f' - Failed to import plyvel; unable to process {ldb_path}')
        return []

    # The ldb key and value are both bytearrays, so the prefix must be too. We allow
    # passing the prefix into this function as a string for convenience.
    if isinstance(prefix, str):
        prefix = prefix.encode()

    try:
        db = plyvel.DB(ldb_path, create_if_missing=False)
    except Exception as e:
        log.warning(f' - Couldn\'t open {ldb_path} as LevelDB; {e}')
        return []

    cleaned_pairs = []
    pairs = list(db.iterator())
    for pair in pairs:
        # Each leveldb pair should be a tuple of length 2 (key & value); if not, log it and skip it.
        if not isinstance(pair, tuple) or len(pair) is not 2:
            log.warning(f' - Found LevelDB key/value pair that is not formed as expected ({str(pair)}); skipping.')
            continue

        key, value = pair
        if key.startswith(prefix):
            key = key[len(prefix):]
            cleaned_pairs.append({'key': key, 'value': value})

    return cleaned_pairs 
開發者ID:obsidianforensics,項目名稱:hindsight,代碼行數:37,代碼來源:utils.py

示例13: get_chainstate_lastblock

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def get_chainstate_lastblock(fin_name=CFG.chainstate_path):
    """
    Gets the block hash of the last block a given chainstate folder is updated to.
    :param fin_name: chainstate folder name
    :type fin_name: str
    :return: The block hash (Big Endian)
    :rtype: str
    """

    # Open the chainstate
    db = plyvel.DB(fin_name, compression=None)

    # Load obfuscation key (if it exists)
    o_key = db.get((unhexlify("0e00") + "obfuscate_key"))

    # Get the key itself (the leading byte indicates only its size)
    if o_key is not None:
        o_key = hexlify(o_key)[2:]

    # Get the obfuscated block hash
    o_height = db.get(b'B')

    # Deobfuscate the height
    height = deobfuscate_value(o_key, hexlify(o_height))

    return change_endianness(height) 
開發者ID:sr-gi,項目名稱:bitcoin_tools,代碼行數:28,代碼來源:utils.py

示例14: get_utxo

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def get_utxo(tx_id, index, fin_name=CFG.chainstate_path):
    """
    Gets a UTXO from the chainstate identified by a given transaction id and index.
    If the requested UTXO does not exist, return None.

    :param tx_id: Transaction ID that identifies the UTXO you are looking for.
    :type tx_id: str
    :param index: Index that identifies the specific output.
    :type index: int
    :param fin_name: Name of the LevelDB folder (chainstate by default)
    :type fin_name: str
    :return: A outpoint:coin pair representing the requested UTXO
    :rtype: str, str
    """

    prefix = b'C'
    outpoint = prefix + unhexlify(tx_id + b128_encode(index))

    # Open the LevelDB
    db = plyvel.DB(fin_name, compression=None)  # Change with path to chainstate

    # Load obfuscation key (if it exists)
    o_key = db.get((unhexlify("0e00") + "obfuscate_key"))

    # If the key exists, the leading byte indicates the length of the key (8 byte by default). If there is no key,
    # 8-byte zeros are used (since the key will be XORed with the given values).
    if o_key is not None:
        o_key = hexlify(o_key)[2:]

    coin = db.get(outpoint)

    if coin is not None and o_key is not None:
        coin = deobfuscate_value(o_key, hexlify(coin))

    db.close()

    return hexlify(outpoint), coin 
開發者ID:sr-gi,項目名稱:bitcoin_tools,代碼行數:39,代碼來源:utils.py

示例15: init_ldb_storage

# 需要導入模塊: import plyvel [as 別名]
# 或者: from plyvel import DB [as 別名]
def init_ldb_storage():
    if not settings.TESTING:
        _storage_ldb = plyvel.DB(settings.LEVELDB_BLOCKCHAIN_ADDRESS, create_if_missing=True)
    else:
        from unittest.mock import Mock
        _storage_ldb = Mock()
    _local.in_ldb_batch = False
    _local.ldb = _storage_ldb
    return _storage_ldb 
開發者ID:gdassori,項目名稱:spruned,代碼行數:11,代碼來源:database.py


注:本文中的plyvel.DB屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。