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


Python OrderedDict.setdefault方法代碼示例

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


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

示例1: get_vms_per_type

# 需要導入模塊: from salt.utils.odict import OrderedDict [as 別名]
# 或者: from salt.utils.odict.OrderedDict import setdefault [as 別名]
def get_vms_per_type(target):
    '''Return all vms indexed by virt_type for a special target'''
    all_targets = OrderedDict()
    for virt_type in VIRT_TYPES:
        per_type = all_targets.setdefault(virt_type, set())
        all_infos = get_targets_and_vms_for_virt_type(virt_type)
        for vmname in all_infos.get(target, []):
            per_type.add(vmname)
    for i in [a for a in all_targets]:
        all_targets[i] = [a for a in all_targets[i]]
    return all_targets
開發者ID:jpcw,項目名稱:makina-states,代碼行數:13,代碼來源:mc_cloud_compute_node.py

示例2: element

# 需要導入模塊: from salt.utils.odict import OrderedDict [as 別名]
# 或者: from salt.utils.odict.OrderedDict import setdefault [as 別名]
    def element(self, root=None, abspath=None, **kwargs):
        '''
        kwargs contain extra information for custom methods.

        This method must return a valid empty object if no vars are passed
        to allow introspection to create patterns.

        :param root:
        :param abspath:
        '''
        if root is None and abspath is None:
            root = os.path.abspath('.')
            abspath = os.path.abspath('.')
        relpath = os.path.relpath(abspath, root)

        try:
            element = self._elements.get(relpath, OrderedDict())
        except AttributeError:
            element = OrderedDict()

        if not element:
            for field in PATHINFO_FIELDS:
                element.setdefault(field, '')
            element['saltenv'] = kwargs.get('saltenv', 'base')
            element['relpath'] = relpath
            element['abspath'] = abspath
            element['is_pillar'] = kwargs.get('is_pillar', False)

        cachedir = kwargs.get('cachedir', '')
        if cachedir and os.path.commonprefix([abspath, cachedir]) == cachedir:
            element['cache_root'] = root
        else:
            element['file_root'] = root

        element_hook = kwargs.get('_element_hook', None)
        if element_hook:
            element = element_hook(self, element, **kwargs)

        return element
開發者ID:joesaland,項目名稱:qubes-mgmt-salt-base-topd,代碼行數:41,代碼來源:pathinfo.py

示例3: get_vms

# 需要導入模塊: from salt.utils.odict import OrderedDict [as 別名]
# 或者: from salt.utils.odict.OrderedDict import setdefault [as 別名]
def get_vms():
    '''Return all vms indexed by targets'''
    data = OrderedDict()
    for virt_type in VIRT_TYPES:
        all_infos = get_targets_and_vms_for_virt_type(virt_type)
        for t in all_infos:
            target = data.setdefault(t, {})
            vms = {}
            vts = set()
            for vmname in all_infos[t]:
                vms.setdefault(vmname, virt_type)
                vts.add(virt_type)
            target['virt_types'] = [a for a in vts]
            target['vms'] = vms
    return data
開發者ID:jpcw,項目名稱:makina-states,代碼行數:17,代碼來源:mc_cloud_compute_node.py


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