當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。