Пример #1
0
    def import_unknown_metadata_files(self, metadata_files):
        """
        Import metadata files whose type is not known to us. These are any files
        that we are not already parsing.

        :param metadata_files:  object containing access to all metadata files
        :type  metadata_files:  pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
        """
        for metadata_type, file_info in metadata_files.metadata.iteritems():
            if metadata_type not in metadata_files.KNOWN_TYPES:
                checksum_type = file_info['checksum']['algorithm']
                checksum_type = verification.sanitize_checksum_type(
                    checksum_type)

                unit_metadata = {
                    'checksum': file_info['checksum']['hex_digest'],
                    'checksum_type': checksum_type,
                }
                model = models.YumMetadataFile(metadata_type,
                                               self.sync_conduit.repo_id,
                                               unit_metadata)
                relative_path = os.path.join(
                    model.relative_dir,
                    os.path.basename(file_info['local_path']))
                unit = self.sync_conduit.init_unit(models.YumMetadataFile.TYPE,
                                                   model.unit_key,
                                                   model.metadata,
                                                   relative_path)
                shutil.copyfile(file_info['local_path'], unit.storage_path)
                self.sync_conduit.save_unit(unit)
Пример #2
0
    def import_unknown_metadata_files(self, metadata_files):
        """
        Import metadata files whose type is not known to us. These are any files
        that we are not already parsing.

        :param metadata_files:  object containing access to all metadata files
        :type  metadata_files:  pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
        """
        for metadata_type, file_info in metadata_files.metadata.iteritems():
            if metadata_type not in metadata_files.KNOWN_TYPES:
                file_path = file_info['local_path']
                checksum_type = file_info['checksum']['algorithm']
                checksum_type = verification.sanitize_checksum_type(
                    checksum_type)
                checksum = file_info['checksum']['hex_digest']
                # Find an existing model
                model = models.YumMetadataFile.objects.filter(
                    data_type=metadata_type,
                    repo_id=self.repo.repo_id).first()
                # If an existing model, use that
                if model:
                    model.checksum = checksum
                    model.checksum_type = checksum_type
                else:
                    # Else, create a  new mode
                    model = models.YumMetadataFile(data_type=metadata_type,
                                                   repo_id=self.repo.repo_id,
                                                   checksum=checksum,
                                                   checksum_type=checksum_type)

                model.set_storage_path(os.path.basename(file_path))
                model.save_and_import_content(file_path)

                # associate/re-associate model to the repo
                repo_controller.associate_single_unit(self.repo, model)
Пример #3
0
def _handle_yum_metadata_file(repo, type_id, unit_key, metadata, file_path,
                              conduit, config):
    """
    Handles the upload for a yum repository metadata file.

    :type  repo: pulp.plugins.model.Repository
    :type  type_id: str
    :type  unit_key: dict
    :type  metadata: dict or None
    :type  file_path: str
    :type  conduit: pulp.plugins.conduits.upload.UploadConduit
    :type  config: pulp.plugins.config.PluginCallConfiguration
    """

    # Validate the user specified data by instantiating the model
    try:
        model = models.YumMetadataFile(metadata=metadata, **unit_key)
    except TypeError:
        raise ModelInstantiationError()

    # Replicates the logic in yum/sync.py.import_unknown_metadata_files.
    # The local_path variable is removed since it's not included in the metadata when
    # synchronized.
    file_relative_path = model.metadata.pop('local_path')
    relative_path = os.path.join(model.relative_dir, file_relative_path)

    # Move the file to its final storage location in Pulp
    try:
        unit = conduit.init_unit(model.TYPE, model.unit_key, model.metadata,
                                 relative_path)
        shutil.move(file_path, unit.storage_path)
        conduit.save_unit(unit)
    except IOError:
        raise StoreFileError()
Пример #4
0
def _handle_yum_metadata_file(repo, type_id, unit_key, metadata, file_path,
                              conduit, config):
    """
    Handles the upload for a Yum repository metadata file.

    :param repo: The repository to import the package into
    :type  repo: pulp.server.db.model.Repository

    :param type_id: The type_id of the package being uploaded
    :type  type_id: str

    :param unit_key: A dictionary of fields to overwrite introspected field values
    :type  unit_key: dict

    :param metadata: A dictionary of fields to overwrite introspected field values, or None
    :type  metadata: dict or None

    :param file_path: The path to the uploaded package
    :type  file_path: str

    :param conduit: provides access to relevant Pulp functionality
    :type  conduit: pulp.plugins.conduits.upload.UploadConduit

    :param config: plugin configuration for the repository
    :type  config: pulp.plugins.config.PluginCallConfiguration
    """
    model_class = plugin_api.get_unit_model_by_id(type_id)
    update_fields_inbound(model_class, unit_key or {})
    update_fields_inbound(model_class, metadata or {})

    unit_data = {}
    unit_data.update(metadata or {})
    unit_data.update(unit_key or {})

    model = models.YumMetadataFile(**unit_data)
    model.set_storage_path(os.path.basename(file_path))
    try:
        model.save_and_import_content(file_path)
    except NotUniqueError:
        model = model.__class__.objects.get(**model.unit_key)

    repo_controller.associate_single_unit(conduit.repo, model)
Пример #5
0
def yum_md_file():
    return models.YumMetadataFile(models.YumMetadataFile.TYPE,
                                  'repo-%d' % _yum_md_file_counter.next(), {})