Ejemplo n.º 1
0
def create_iso(target_dir, output_dir, prefix, image_size=DVD_ISO_SIZE, progress_callback=None):
    """
    Run the export process.

    :param target_dir:          The directory to be written to ISO images
    :type  target_dir:          str
    :param output_dir:          destination directory where the ISO images are written
    :type  output_dir:          str
    :param prefix:              prefix for the ISO file names; usually includes a repo id
    :type  prefix:              str
    :param image_size:          The maximum size of the image in bytes. Defaults to a dvd sized image.
    :type  image_size:          int
    :param progress_callback:   callback to report progress info to publish_conduit. This is expected to
                                take the following parameters: a string to use as the key in a
                                dictionary, and the second parameter is assigned to it.
    :type  progress_callback:   function
    """
    # Validate the configuration
    image_size = _parse_image_size(image_size)

    # record start time
    start_time = datetime.datetime.now()

    # get size and file list of the target directory
    file_list, total_dir_size = _get_dir_file_list_and_size(target_dir)

    # image_list is a list of the images to write. Each item in the list is a list of file paths.
    image_list = _compute_image_files(file_list, image_size)
    image_count = len(image_list)

    # Update the progress report
    iso_progress_status = export_utils.init_progress_report(image_count)
    set_progress("isos", iso_progress_status, progress_callback)

    for i in range(image_count):
        name = "%s-%s-%02d.iso" % (prefix, start_time.strftime("%Y-%m-%dT%H.%M"), i + 1)
        _make_iso(image_list[i], target_dir, output_dir, name)

        # Update the progress report
        iso_progress_status[constants.PROGRESS_ITEMS_LEFT_KEY] -= 1
        iso_progress_status[constants.PROGRESS_NUM_SUCCESS_KEY] += 1
        set_progress("isos", iso_progress_status, progress_callback)

    iso_progress_status["state"] = constants.STATE_COMPLETE
    set_progress("isos", iso_progress_status, progress_callback)
Ejemplo n.º 2
0
    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)