当前位置: 首页>>代码示例>>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;未经允许,请勿转载。