当前位置: 首页>>代码示例>>Python>>正文


Python Module.from_dict方法代码示例

本文整理汇总了Python中pulp_puppet.common.model.Module.from_dict方法的典型用法代码示例。如果您正苦于以下问题:Python Module.from_dict方法的具体用法?Python Module.from_dict怎么用?Python Module.from_dict使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pulp_puppet.common.model.Module的用法示例。


在下文中一共展示了Module.from_dict方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _generate_metadata

# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_dict [as 别名]
    def _generate_metadata(self, modules):
        """
        Generates the repository metadata document for all modules in the

        :type modules: list of pulp.plugins.model.AssociatedUnit
        """
        _logger.info('Generating metadata for repository <%s>' % self.repo.id)

        # Convert the Pulp data types into the local model
        metadata = RepositoryMetadata()

        for m in modules:
            combined = copy.copy(m.unit_key)
            combined.update(m.metadata)
            module = Module.from_dict(combined)
            metadata.modules.append(module)

        # Write the JSON representation of the metadata to the repository
        json_metadata = metadata.to_json()
        build_dir = self._build_dir()
        metadata_file = os.path.join(build_dir, constants.REPO_METADATA_FILENAME)

        f = open(metadata_file, 'w')
        f.write(json_metadata)
        f.close()
开发者ID:bmbouter,项目名称:pulp_puppet,代码行数:27,代码来源:publish.py

示例2: test_from_dict

# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_dict [as 别名]
    def test_from_dict(self):
        # Setup
        data = json.loads(VALID_MODULE_METADATA_JSON)

        # Test
        module = Module.from_dict(data)

        # Verify
        self.assert_valid_module(module)
开发者ID:jlsherrill,项目名称:pulp,代码行数:11,代码来源:test_common_model.py

示例3: handle_uploaded_unit

# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_dict [as 别名]
def handle_uploaded_unit(repo, type_id, unit_key, metadata, file_path, conduit):
    """
    Handles an upload unit request to the importer. This call is responsible
    for moving the unit from its temporary location where Pulp stored the
    upload to the final storage location (as dictated by Pulp) for the unit.
    This call will also update the database in Pulp to reflect the unit
    and its association to the repository.

    :param repo: repository into which the unit is being uploaded
    :type  repo: pulp.plugins.model.Repository
    :param type_id: type of unit being uploaded
    :type  type_id: str
    :param unit_key: unique identifier for the unit
    :type  unit_key: dict
    :param metadata: extra data about the unit
    :type  metadata: dict
    :param file_path: temporary location of the uploaded file
    :type  file_path: str
    :param conduit: for calls back into Pulp
    :type  conduit: pulp.plugins.conduit.upload.UploadConduit
    """

    if type_id != constants.TYPE_PUPPET_MODULE:
        raise NotImplementedError()

    # Create a module with unit_key if supplied
    initial_module = None
    if unit_key:
        initial_module = Module.from_dict(unit_key)

    # Extract the metadata from the module
    extracted_data = metadata_parser.extract_metadata(file_path, repo.working_dir, initial_module)
    checksum = metadata_parser.calculate_checksum(file_path)

    # Create a module from the metadata
    module = Module.from_json(extracted_data)
    module.checksum = checksum

    # Create the Pulp unit
    type_id = constants.TYPE_PUPPET_MODULE
    unit_key = module.unit_key()
    unit_metadata = module.unit_metadata()
    relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

    unit = conduit.init_unit(type_id, unit_key, unit_metadata, relative_path)

    # Copy from the upload temporary location into where Pulp wants it to live
    shutil.copy(file_path, unit.storage_path)

    # Save the unit into the destination repository
    conduit.save_unit(unit)

    return {'success_flag': True, 'summary': '', 'details': {}}
开发者ID:asmacdo,项目名称:pulp_puppet,代码行数:55,代码来源:upload.py

示例4: handle_uploaded_unit

# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_dict [as 别名]
def handle_uploaded_unit(type_id, unit_key, metadata, file_path, conduit):
    """
    Handles an upload unit request to the importer. This call is responsible
    for moving the unit from its temporary location where Pulp stored the
    upload to the final storage location (as dictated by Pulp) for the unit.
    This call will also update the database in Pulp to reflect the unit
    and its association to the repository.

    :param type_id: type of unit being uploaded
    :type  type_id: str
    :param unit_key: unique identifier for the unit
    :type  unit_key: dict
    :param metadata: extra data about the unit
    :type  metadata: dict
    :param file_path: temporary location of the uploaded file
    :type  file_path: str
    :param conduit: for calls back into Pulp
    :type  conduit: pulp.plugins.conduit.upload.UploadConduit
    """

    if type_id != constants.TYPE_PUPPET_MODULE:
        raise NotImplementedError()

    # Create a module out of the uploaded metadata
    combined = copy.copy(unit_key)
    combined.update(metadata)
    module = Module.from_dict(combined)

    # Create the Pulp unit
    type_id = constants.TYPE_PUPPET_MODULE
    unit_key = module.unit_key()
    unit_metadata = module.unit_metadata()
    relative_path = constants.STORAGE_MODULE_RELATIVE_PATH % module.filename()

    unit = conduit.init_unit(type_id, unit_key, unit_metadata, relative_path)

    # Copy from the upload temporary location into where Pulp wants it to live
    shutil.copy(file_path, unit.storage_path)

    # Save the unit into the destination repository
    conduit.save_unit(unit)

    
开发者ID:jlsherrill,项目名称:pulp,代码行数:43,代码来源:upload.py

示例5: _import_modules

# 需要导入模块: from pulp_puppet.common.model import Module [as 别名]
# 或者: from pulp_puppet.common.model.Module import from_dict [as 别名]
    def _import_modules(self, inventory, module_paths):
        """
        Import the puppet modules (tarballs) at the specified paths.

        :param inventory: A module inventory object.
        :type inventory: Inventory
        :param module_paths: A list of paths to puppet module files.
        :type module_paths: list
        :return: A list of the imported module unit keys.
        :rtype: list
        """
        imported_modules = []
        for module_path in module_paths:
            if self.canceled:
                return []
            puppet_manifest = self._extract_metadata(module_path)
            module = Module.from_dict(puppet_manifest)
            if inventory.already_associated(module):
                continue
            _LOG.info(IMPORT_MODULE % dict(mod=module_path))
            imported_modules.append(module.unit_key())
            self._add_module(module_path, module)
        return imported_modules
开发者ID:christoe,项目名称:pulp_puppet,代码行数:25,代码来源:directory.py


注:本文中的pulp_puppet.common.model.Module.from_dict方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。