当前位置: 首页>>代码示例>>Python>>正文


Python unitdata.kv方法代码示例

本文整理汇总了Python中charmhelper.core.unitdata.kv方法的典型用法代码示例。如果您正苦于以下问题:Python unitdata.kv方法的具体用法?Python unitdata.kv怎么用?Python unitdata.kv使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在charmhelper.core.unitdata的用法示例。


在下文中一共展示了unitdata.kv方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getrange

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def getrange(self, key_prefix, strip=False):
        """
        Get a range of keys starting with a common prefix as a mapping of
        keys to values.

        :param str key_prefix: Common prefix among all keys
        :param bool strip: Optionally strip the common prefix from the key
            names in the returned dict
        :return dict: A (possibly empty) dict of key-value mappings
        """
        self.cursor.execute("select key, data from kv where key like ?",
                            ['%s%%' % key_prefix])
        result = self.cursor.fetchall()

        if not result:
            return {}
        if not strip:
            key_prefix = ''
        return dict([
            (k[len(key_prefix):], json.loads(v)) for k, v in result]) 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:22,代码来源:unitdata.py

示例2: unsetrange

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def unsetrange(self, keys=None, prefix=""):
        """
        Remove a range of keys starting with a common prefix, from the database
        entirely.

        :param list keys: List of keys to remove.
        :param str prefix: Optional prefix to apply to all keys in ``keys``
            before removing.
        """
        if keys is not None:
            keys = ['%s%s' % (prefix, key) for key in keys]
            self.cursor.execute('delete from kv where key in (%s)' % ','.join(['?'] * len(keys)), keys)
            if self.revision and self.cursor.rowcount:
                self.cursor.execute(
                    'insert into kv_revisions values %s' % ','.join(['(?, ?, ?)'] * len(keys)),
                    list(itertools.chain.from_iterable((key, self.revision, json.dumps('DELETED')) for key in keys)))
        else:
            self.cursor.execute('delete from kv where key like ?',
                                ['%s%%' % prefix])
            if self.revision and self.cursor.rowcount:
                self.cursor.execute(
                    'insert into kv_revisions values (?, ?, ?)',
                    ['%s%%' % prefix, self.revision, json.dumps('DELETED')]) 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:25,代码来源:unitdata.py

示例3: _init

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def _init(self):
        self.cursor.execute('''
            create table if not exists kv (
               key text,
               data text,
               primary key (key)
               )''')
        self.cursor.execute('''
            create table if not exists kv_revisions (
               key text,
               revision integer,
               data text,
               primary key (key, revision)
               )''')
        self.cursor.execute('''
            create table if not exists hooks (
               version integer primary key autoincrement,
               hook text,
               date text
               )''')
        self.conn.commit() 
开发者ID:openstack,项目名称:charm-swift-proxy,代码行数:23,代码来源:unitdata.py

示例4: get

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def get(self, key, default=None, record=False):
        self.cursor.execute('select data from kv where key=?', [key])
        result = self.cursor.fetchone()
        if not result:
            return default
        if record:
            return Record(json.loads(result[0]))
        return json.loads(result[0]) 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:10,代码来源:unitdata.py

示例5: unset

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def unset(self, key):
        """
        Remove a key from the database entirely.
        """
        self.cursor.execute('delete from kv where key=?', [key])
        if self.revision and self.cursor.rowcount:
            self.cursor.execute(
                'insert into kv_revisions values (?, ?, ?)',
                [key, self.revision, json.dumps('DELETED')]) 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:11,代码来源:unitdata.py

示例6: gethistory

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def gethistory(self, key, deserialize=False):
        self.cursor.execute(
            '''
            select kv.revision, kv.key, kv.data, h.hook, h.date
            from kv_revisions kv,
                 hooks h
            where kv.key=?
             and kv.revision = h.version
            ''', [key])
        if deserialize is False:
            return self.cursor.fetchall()
        return map(_parse_history, self.cursor.fetchall()) 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:14,代码来源:unitdata.py

示例7: debug

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def debug(self, fh=sys.stderr):
        self.cursor.execute('select * from kv')
        pprint.pprint(self.cursor.fetchall(), stream=fh)
        self.cursor.execute('select * from kv_revisions')
        pprint.pprint(self.cursor.fetchall(), stream=fh) 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:7,代码来源:unitdata.py

示例8: __init__

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def __init__(self):
        self.kv = kv()
        self.conf = None
        self.rels = None 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:6,代码来源:unitdata.py

示例9: __call__

# 需要导入模块: from charmhelper.core import unitdata [as 别名]
# 或者: from charmhelper.core.unitdata import kv [as 别名]
def __call__(self):
        from charmhelpers.core import hookenv
        hook_name = hookenv.hook_name()

        with self.kv.hook_scope(hook_name):
            self._record_charm_version(hookenv.charm_dir())
            delta_config, delta_relation = self._record_hook(hookenv)
            yield self.kv, delta_config, delta_relation 
开发者ID:openstack,项目名称:charm-plumgrid-gateway,代码行数:10,代码来源:unitdata.py


注:本文中的charmhelper.core.unitdata.kv方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。