本文整理汇总了Python中pulp_puppet.common.model.Module.from_unit方法的典型用法代码示例。如果您正苦于以下问题:Python Module.from_unit方法的具体用法?Python Module.from_unit怎么用?Python Module.from_unit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pulp_puppet.common.model.Module
的用法示例。
在下文中一共展示了Module.from_unit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _do_import_modules
# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_unit [as 别名]
def _do_import_modules(self, metadata):
"""
Actual logic of the import. This method will do a best effort per module;
if an individual module fails it will be recorded and the import will
continue. This method will only raise an exception in an extreme case
where it cannot react and continue.
"""
def unit_key_str(unit_key_dict):
"""
Converts the unit key dict form into a single string that can be
used as the key in a dict lookup.
"""
template = '%s-%s-%s'
return template % (encode_unicode(unit_key_dict['name']),
encode_unicode(unit_key_dict['version']),
encode_unicode(unit_key_dict['author']))
downloader = self._create_downloader()
self.downloader = downloader
# Ease lookup of modules
modules_by_key = dict([(unit_key_str(m.unit_key()), m) for m in metadata.modules])
# Collect information about the repository's modules before changing it
module_criteria = UnitAssociationCriteria(type_ids=[constants.TYPE_PUPPET_MODULE])
existing_units = self.sync_conduit.get_units(criteria=module_criteria)
existing_modules = [Module.from_unit(x) for x in existing_units]
existing_module_keys = [unit_key_str(m.unit_key()) for m in existing_modules]
new_unit_keys = self._resolve_new_units(existing_module_keys, modules_by_key.keys())
remove_unit_keys = self._resolve_remove_units(existing_module_keys, modules_by_key.keys())
# Once we know how many things need to be processed, we can update the
# progress report
self.progress_report.modules_total_count = len(new_unit_keys)
self.progress_report.modules_finished_count = 0
self.progress_report.modules_error_count = 0
self.progress_report.update_progress()
# Add new units
for key in new_unit_keys:
if self._canceled:
break
module = modules_by_key[key]
try:
self._add_new_module(downloader, module)
self.progress_report.modules_finished_count += 1
except Exception, e:
self.progress_report.add_failed_module(module, e, sys.exc_info()[2])
self.progress_report.update_progress()
示例2: _associated
# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_unit [as 别名]
def _associated(conduit):
"""
Retrieve the modules associated with a repository, build a set containing
the unit_key for each and return it.
:param conduit: Provides access to relevant Pulp functionality.
:type conduit: pulp.plugins.conduits.unit_import.ImportUnitConduit
:return: The set of unit keys.
:rtype: set
"""
key_set = set()
criteria = UnitAssociationCriteria(
type_ids=[constants.TYPE_PUPPET_MODULE], unit_fields=Module.UNIT_KEY_NAMES)
units = conduit.get_units(criteria=criteria, as_generator=True)
for unit in units:
module = Module.from_unit(unit)
key_set.add(tuple(module.unit_key().items()))
return key_set