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


Python OrderedDict.pop方法代碼示例

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


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

示例1: get_local_registry

# 需要導入模塊: from salt.utils.odict import OrderedDict [as 別名]
# 或者: from salt.utils.odict.OrderedDict import pop [as 別名]
def get_local_registry(name,
                       cached=True,
                       cachetime=60,
                       registry_format='yaml'):
    '''Get local registry
    Masteralt & Salt share the local registries
    unless for the main ones:

        - controllers
        - services
        - nodetypes
        - localsettings
        - cloud

    For backward compatibility, we take care to load and merge
    shared registries in mastersalt & salt prefix if any is found.
    '''
    not_shared = ['controllers', 'services', 'nodetypes',
                  'localsettings', 'cloud']
    mastersalt_registryf = '{0}/makina-states/{1}.{2}'.format(
        '/etc/mastersalt',  name, registry_format)
    salt_registryf = '{0}/makina-states/{1}.{2}'.format(
        '/etc/salt',  name, registry_format)
    shared_registryf = os.path.join(
        '/etc/makina-states/{0}.{1}'.format(name, registry_format))
    registry = OrderedDict()
    # cache local registries one minute
    pkey = '{0}____'.format(name)
    key = '{0}{1}'.format(pkey, time.time() // cachetime)
    if name not in not_shared:
        to_load = [mastersalt_registryf,
                   salt_registryf,
                   shared_registryf]
    else:
        to_load = [
            '{0}/makina-states/{1}.{2}'.format(
                __opts__['config_dir'], name, registry_format)
        ]
    if (key not in _LOCAL_REG_CACHE) or (not cached):
        invalidate_cached_registry(name)
        for registryf in to_load:
            dregistry = os.path.dirname(registryf)
            if not os.path.exists(dregistry):
                os.makedirs(dregistry)
            if os.path.exists(registryf):
                _LOCAL_REG_CACHE[key] = registry = __salt__[
                    'mc_utils.dictupdate'](
                        registry,
                        __salt__[
                            'mc_macros.{0}_load_local_registry'.format(
                                registry_format)](name, registryf))
                # unprefix local simple registries
                loc_k = DEFAULT_LOCAL_REG_NAME.format(name)
                for k in [t for t in registry if t.startswith(loc_k)]:
                    spl = loc_k + '.'
                    nk = spl.join(k.split(spl)[1:])
                    registry[nk] = registry[k]
                    registry.pop(k)
    elif cached:
        registry = _LOCAL_REG_CACHE[key]
    return registry
開發者ID:jpcw,項目名稱:makina-states,代碼行數:63,代碼來源:mc_macros.py


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