本文整理汇总了Python中salt.utils.odict.OrderedDict.update方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.update方法的具体用法?Python OrderedDict.update怎么用?Python OrderedDict.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类salt.utils.odict.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.update方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gen_ini
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import update [as 别名]
def gen_ini(self):
yield '\n[{0}]\n'.format(self.name)
sections_dict = OrderedDict()
for name, value in self.iteritems():
if com_regx.match(name):
yield '{0}\n'.format(value)
elif isinstance(value, _Section):
sections_dict.update({name: value})
else:
yield '{0} {1} {2}\n'.format(name, self.sep, value)
for name, value in sections_dict.iteritems():
for line in value.gen_ini():
yield line
示例2: gen_ini
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import update [as 别名]
def gen_ini(self):
yield "{0}[{1}]{0}".format(os.linesep, self.name)
sections_dict = OrderedDict()
for name, value in six.iteritems(self):
if com_regx.match(name):
yield "{0}{1}".format(value, os.linesep)
elif isinstance(value, _Section):
sections_dict.update({name: value})
else:
yield "{0}{1}{2}{3}".format(
name, (" {0} ".format(self.sep) if self.sep != " " else self.sep), value, os.linesep
)
for name, value in six.iteritems(sections_dict):
for line in value.gen_ini():
yield line
示例3: _uncomment_if_commented
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import update [as 别名]
def _uncomment_if_commented(self, opt_key):
# should be called only if opt_key is not already present
# will uncomment the key if commented and create a place holder
# for the key where the correct value can be update later
# used to preserve the ordering of comments and commented options
# and to make sure options without sectons go above any section
options_backup = OrderedDict()
comment_index = None
for key, value in self.iteritems():
if comment_index is not None:
options_backup.update({key: value})
continue
if '#comment' not in key:
continue
opt_match = opt_regx.match(value.lstrip('#'))
if opt_match and opt_match.group(2) == opt_key:
comment_index = key
for key in options_backup:
self.pop(key)
self.pop(comment_index, None)
super(_Section, self).update({opt_key: None})
for key, value in options_backup.iteritems():
super(_Section, self).update({key: value})
示例4: managed
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import update [as 别名]
#.........这里部分代码省略.........
'new': {'attr2': ['val3']}}}
* ``'result'``
One of the following values:
* ``True`` if no changes were necessary or if all changes
were applied successfully.
* ``False`` if at least one change was unable to be applied.
* ``None`` if changes would be applied but it is in test
mode.
'''
if connect_spec is None:
connect_spec = {}
try:
connect_spec.setdefault('url', name)
except AttributeError:
# already a connection object
pass
connect = __salt__['ldap3.connect']
# hack to get at the ldap3 module to access the ldap3.LDAPError
# exception class. https://github.com/saltstack/salt/issues/27578
ldap3 = inspect.getmodule(connect)
with connect(connect_spec) as l:
old, new = _process_entries(l, entries)
# collect all of the affected entries (only the key is
# important in this dict; would have used an OrderedSet if
# there was one)
dn_set = OrderedDict()
dn_set.update(old)
dn_set.update(new)
# do some cleanup
dn_to_delete = set()
for dn in dn_set:
o = old.get(dn, {})
n = new.get(dn, {})
for x in o, n:
to_delete = set()
for attr, vals in six.iteritems(x):
if not len(vals):
# clean out empty attribute lists
to_delete.add(attr)
for attr in to_delete:
del x[attr]
if o == n:
# clean out unchanged entries
dn_to_delete.add(dn)
for dn in dn_to_delete:
for x in old, new:
x.pop(dn, None)
del dn_set[dn]
ret = {
'name': name,
'changes': {},
'result': None,
'comment': '',
}
if old == new:
ret['comment'] = 'LDAP entries already set'
示例5: gen_functions
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import update [as 别名]
def gen_functions(self, pack=None, virtual_enable=True, whitelist=None,
provider_overrides=False):
'''
Return a dict of functions found in the defined module_dirs
'''
funcs = OrderedDict()
self.load_modules()
for mod in self.modules:
# If this is a proxy minion then MOST modules cannot work. Therefore, require that
# any module that does work with salt-proxy-minion define __proxyenabled__ as a list
# containing the names of the proxy types that the module supports.
if not hasattr(mod, 'render') and 'proxy' in self.opts:
if not hasattr(mod, '__proxyenabled__'):
# This is a proxy minion but this module doesn't support proxy
# minions at all
continue
if not (self.opts['proxy']['proxytype'] in mod.__proxyenabled__ or
'*' in mod.__proxyenabled__):
# This is a proxy minion, this module supports proxy
# minions, but not this particular minion
log.debug(mod)
continue
if hasattr(mod, '__opts__'):
mod.__opts__.update(self.opts)
else:
mod.__opts__ = self.opts
mod.__grains__ = self.grains
mod.__pillar__ = self.pillar
if pack:
if isinstance(pack, list):
for chunk in pack:
if not isinstance(chunk, dict):
continue
try:
setattr(mod, chunk['name'], chunk['value'])
except KeyError:
pass
else:
setattr(mod, pack['name'], pack['value'])
# Call a module's initialization method if it exists
if hasattr(mod, '__init__'):
if callable(mod.__init__):
try:
mod.__init__(self.opts)
except TypeError:
pass
# Trim the full pathname to just the module
# this will be the short name that other salt modules and state
# will refer to it as.
module_name = mod.__name__.rsplit('.', 1)[-1]
if virtual_enable:
# if virtual modules are enabled, we need to look for the
# __virtual__() function inside that module and run it.
(virtual_ret, virtual_name) = self.process_virtual(mod,
module_name)
# if process_virtual returned a non-True value then we are
# supposed to not process this module
if virtual_ret is not True:
continue
# update our module name to reflect the virtual name
module_name = virtual_name
if whitelist:
# If a whitelist is defined then only load the module if it is
# in the whitelist
if module_name not in whitelist:
continue
# load the functions from the module and update our dict
funcs.update(self.load_functions(mod, module_name))
# Handle provider overrides
if provider_overrides and self.opts.get('providers', False):
if isinstance(self.opts['providers'], dict):
for mod, provider in self.opts['providers'].items():
newfuncs = raw_mod(self.opts, provider, funcs)
if newfuncs:
for newfunc in newfuncs:
f_key = '{0}{1}'.format(
mod, newfunc[newfunc.rindex('.'):]
)
funcs[f_key] = newfuncs[newfunc]
# now that all the functions have been collected, iterate back over
# the available modules and inject the special __salt__ namespace that
# contains these functions.
for mod in self.modules:
if not hasattr(mod, '__salt__') or (
not in_pack(pack, '__salt__') and
(not str(mod.__name__).startswith('salt.loaded.int.grain') and
not str(mod.__name__).startswith('salt.loaded.ext.grain'))
):
#.........这里部分代码省略.........
示例6: serialize
# 需要导入模块: from salt.utils.odict import OrderedDict [as 别名]
# 或者: from salt.utils.odict.OrderedDict import update [as 别名]
def serialize(cls, id_=None):
# The order matters
serialized = OrderedDict()
if id_ is not None:
# This is meant as a configuration section, sub json schema
serialized['id'] = '{0}/{1}.json#'.format(BASE_SCHEMA_URL, id_)
else:
# Main configuration block, json schema
serialized['$schema'] = 'http://json-schema.org/draft-04/schema#'
if cls.title is not None:
serialized['title'] = cls.title
if cls.description is not None:
if cls.description == cls.__doc__:
serialized['description'] = textwrap.dedent(cls.description).strip()
else:
serialized['description'] = cls.description
required = []
ordering = []
serialized['type'] = 'object'
properties = OrderedDict()
cls.after_items_update = []
for name in cls._order:
skip_order = False
if name in cls._sections:
section = cls._sections[name]
serialized_section = section.serialize(None if section.__flatten__ is True else name)
if section.__flatten__ is True:
# Flatten the configuration section into the parent
# configuration
properties.update(serialized_section['properties'])
if 'x-ordering' in serialized_section:
ordering.extend(serialized_section['x-ordering'])
if 'required' in serialized_section:
required.extend(serialized_section['required'])
if hasattr(section, 'after_items_update'):
cls.after_items_update.extend(section.after_items_update)
skip_order = True
else:
# Store it as a configuration section
properties[name] = serialized_section
if name in cls._items:
config = cls._items[name]
# Handle the configuration items defined in the class instance
if config.__flatten__ is True:
serialized_config = config.serialize()
cls.after_items_update.append(serialized_config)
skip_order = True
else:
properties[name] = config.serialize()
if config.required:
# If it's a required item, add it to the required list
required.append(name)
if skip_order is False:
# Store the order of the item
if name not in ordering:
ordering.append(name)
if properties:
serialized['properties'] = properties
# Update the serialized object with any items to include after properties
if cls.after_items_update:
after_items_update = {}
for entry in cls.after_items_update:
name, data = next(six.iteritems(entry))
if name in after_items_update:
after_items_update[name].extend(data)
else:
after_items_update[name] = data
serialized.update(after_items_update)
if required:
# Only include required if not empty
serialized['required'] = required
if ordering:
# Only include ordering if not empty
serialized['x-ordering'] = ordering
serialized['additionalProperties'] = cls.__allow_additional_items__
return serialized