本文整理汇总了Python中salt.utils.odict.OrderedDict.items方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.items方法的具体用法?Python OrderedDict.items怎么用?Python OrderedDict.items使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.utils.odict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.items方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _prompt_choice
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import items [as 别名]
def _prompt_choice(var_name, options):
'''
Prompt the user to choose between a list of options, index each one by adding an enumerator
based on https://github.com/audreyr/cookiecutter/blob/master/cookiecutter/prompt.py#L51
:param var_name: The question to ask the user
:type var_name: ``str``
:param options: A list of options
:type options: ``list`` of ``tupple``
:rtype: ``tuple``
:returns: The selected user
'''
choice_map = OrderedDict(
(u'{0}'.format(i), value) for i, value in enumerate(options, 1) if value[0] != 'test'
)
choices = choice_map.keys()
default = u'1'
choice_lines = [u'{0} - {1} - {2}'.format(c[0], c[1][0], c[1][1]) for c in choice_map.items()]
prompt = u'\n'.join((
u'Select {0}:'.format(var_name),
u'\n'.join(choice_lines),
u'Choose from {0}'.format(u', '.join(choices))
))
user_choice = click.prompt(
prompt, type=click.Choice(choices), default=default
)
return choice_map[user_choice]
示例2: OrderedDict
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import items [as 别名]
# -*- coding: utf-8 -*-
'''
Application Kinds of Salt apps.
These are used to indicate what kind of Application is using RAET
'''
from __future__ import absolute_import
from collections import namedtuple
from salt.utils.odict import OrderedDict
# Python equivalent of an enum
APPL_KINDS = OrderedDict([('master', 0),
('minion', 1),
('syndic', 2),
('caller', 3)])
APPL_KIND_NAMES = OrderedDict((v, k) for k, v in list(APPL_KINDS.items())) # inverse map
ApplKind = namedtuple('ApplKind', list(APPL_KINDS.keys()))
applKinds = ApplKind(**APPL_KINDS)