def publish_group(self, repo_group, publish_conduit, config):
        """
        Publishes the given repository group.

        :param repo_group:      metadata describing the repository group
        :type  repo_group:      pulp.plugins.model.RepositoryGroup
        :param publish_conduit: provides access to relevant Pulp functionality
        :type  publish_conduit: pulp.plugins.conduits.repo_publish.RepoGroupPublishConduit
        :param config:          plugin configuration
        :type  config:          pulp.plugins.config.PluginConfiguration
        :return:                report describing the publish run
        :rtype:                 pulp.plugins.model.PublishReport
        """
        # First, validate the configuration because there may be override config options, and currently,
        # validate_config is not called prior to publishing by the manager.
        valid_config, msg = export_utils.validate_export_config(config)
        if not valid_config:
            raise PulpDataException(msg)

        _logger.info("Beginning export of the following repository group: [%s]" % repo_group.id)

        # The progress report for a group publish
        progress_status = {
            constants.PROGRESS_REPOS_KEYWORD: {constants.PROGRESS_STATE_KEY: constants.STATE_NOT_STARTED},
            constants.PROGRESS_ISOS_KEYWORD: {constants.PROGRESS_STATE_KEY: constants.STATE_NOT_STARTED},
            constants.PROGRESS_PUBLISH_HTTP: {constants.PROGRESS_STATE_KEY: constants.STATE_NOT_STARTED},
            constants.PROGRESS_PUBLISH_HTTPS: {constants.PROGRESS_STATE_KEY: constants.STATE_NOT_STARTED},
        }

        def progress_callback(progress_keyword, status):
            """
            Progress callback used to update the progress report for the publish conduit

            :param progress_keyword:    The keyword to assign the status to in the progress report dict
            :type  progress_keyword:    str
            :param status:              The status to assign to the keyword.
            :type  status:              dict
            """
            progress_status[progress_keyword] = status
            publish_conduit.set_progress(progress_status)

        # Before starting, clean out the working directory. Done to remove last published ISOs
        shutil.rmtree(repo_group.working_dir, ignore_errors=True)
        os.makedirs(repo_group.working_dir)

        # Retrieve the configuration for each repository, the skip types, and the date filter
        packed_config = export_utils.retrieve_group_export_config(repo_group, config)
        rpm_repositories, self.date_filter = packed_config

        # Update the progress for the repositories section
        repos_progress = export_utils.init_progress_report(len(rpm_repositories))
        progress_callback(constants.PROGRESS_REPOS_KEYWORD, repos_progress)

        # For every repository, extract the requested types to the working directory
        for repo_id, working_dir in rpm_repositories:
            # Create a repo conduit, which makes sharing code with the export and yum distributors easier
            repo_conduit = RepoPublishConduit(repo_id, publish_conduit.distributor_id)

            # If there is a date filter perform an incremental export, otherwise do everything
            if self.date_filter:
                result = export_utils.export_incremental_content(working_dir, repo_conduit, self.date_filter)
            else:
                result = export_utils.export_complete_repo(repo_id, working_dir, repo_conduit, config)
            if not config.get(constants.EXPORT_DIRECTORY_KEYWORD):
                util.generate_listing_files(repo_group.working_dir, working_dir)
            else:
                export_dir = config.get(constants.EXPORT_DIRECTORY_KEYWORD)
                util.generate_listing_files(export_dir, working_dir)

            self.summary[repo_id] = result[0]
            self.details[repo_id] = result[1]

            repos_progress[constants.PROGRESS_ITEMS_LEFT_KEY] -= 1
            repos_progress[constants.PROGRESS_NUM_SUCCESS_KEY] += 1
            progress_callback(constants.PROGRESS_REPOS_KEYWORD, repos_progress)

        repos_progress[constants.PROGRESS_STATE_KEY] = constants.STATE_COMPLETE
        progress_callback(constants.PROGRESS_REPOS_KEYWORD, repos_progress)

        # If there was no export directory, publish via ISOs
        if not config.get(constants.EXPORT_DIRECTORY_KEYWORD):
            self._publish_isos(repo_group, config, progress_callback)

        for repo_id, repo_dir in rpm_repositories:
            if repo_id in self.details and len(self.details[repo_id]["errors"]) != 0:
                return publish_conduit.build_failure_report(self.summary, self.details)

        self.summary["repositories_exported"] = len(rpm_repositories)
        self.summary["repositories_skipped"] = len(repo_group.repo_ids) - len(rpm_repositories)

        return publish_conduit.build_success_report(self.summary, self.details)
Exemple #2
0
    def publish_repo(self, repo, publish_conduit, config):
        """
        Export a yum repository to a given directory, or to ISO

        :param repo:            metadata describing the repository
        :type  repo:            pulp.plugins.model.Repository
        :param publish_conduit: provides access to relevant Pulp functionality
        :type  publish_conduit: pulp.plugins.conduits.repo_publish.RepoPublishConduit
        :param config:          plugin configuration
        :type  config:          pulp.plugins.config.PluginConfiguration

        :return: report describing the publish run
        :rtype:  pulp.plugins.model.PublishReport
        """
        # First, validate the configuration because there may be override config options, and currently,
        # validate_config is not called prior to publishing by the manager.
        valid_config, msg = export_utils.validate_export_config(config)
        if not valid_config:
            raise PulpDataException(msg)

        _logger.info('Starting export of [%s]' % repo.id)

        progress_status = {
            models.RPM.TYPE: {'state': constants.STATE_NOT_STARTED},
            models.Errata.TYPE: {'state': constants.STATE_NOT_STARTED},
            models.Distribution.TYPE: {'state': constants.STATE_NOT_STARTED},
            models.PackageCategory.TYPE: {'state': constants.STATE_NOT_STARTED},
            models.PackageGroup.TYPE: {'state': constants.STATE_NOT_STARTED},
            'metadata': {'state': constants.STATE_NOT_STARTED},
            'isos': {'state': constants.STATE_NOT_STARTED},
            'publish_http': {'state': constants.STATE_NOT_STARTED},
            'publish_https': {'state': constants.STATE_NOT_STARTED},
        }

        def progress_callback(type_id, status):
            progress_status[type_id] = status
            publish_conduit.set_progress(progress_status)

        # Retrieve a config tuple and unpack it for use
        config_settings = export_utils.retrieve_repo_config(repo, config)
        self.working_dir, self.date_filter = config_settings

        # Before starting, clean out the working directory. Done to remove last published ISOs
        shutil.rmtree(repo.working_dir, ignore_errors=True)
        os.makedirs(repo.working_dir)

        # If a date filter is not present, do a complete export. If it is, do an incremental export.
        if self.date_filter:
            result = export_utils.export_incremental_content(self.working_dir, publish_conduit,
                                                             self.date_filter, progress_callback)
        else:
            result = export_utils.export_complete_repo(repo.id, self.working_dir, publish_conduit,
                                                       config, progress_callback)
        self.summary = result[0]
        self.details = result[1]

        if not config.get(constants.EXPORT_DIRECTORY_KEYWORD):
            # build iso and publish via HTTPS
            self._publish_isos(repo, config, progress_callback)

        if len(self.details['errors']) != 0:
            return publish_conduit.build_failure_report(self.summary, self.details)
        return publish_conduit.build_success_report(self.summary, self.details)