Exemple #1
0
    def __init__(self, repo, sync_conduit, config, is_cancelled_call):
        self.repo = repo
        self.sync_conduit = sync_conduit
        self.config = config
        self.is_cancelled_call = is_cancelled_call

        self.progress_report = SyncProgressReport(sync_conduit)

        self.dist = model.Distribution(**self.config.get(constants.CONFIG_DIST))
Exemple #2
0
    def display_report(self, progress_report):

        # Sync Steps
        if constants.IMPORTER_ID in progress_report:
            sync_report = SyncProgressReport.from_progress_dict(progress_report[constants.IMPORTER_ID])
            self._display_sync_metadata_step(sync_report)
            self._display_sync_packages_step(sync_report)

        # Publish Steps
        if constants.DISTRIBUTOR_ID in progress_report:
            publish_report = PublishProgressReport.from_progress_dict(progress_report[constants.DISTRIBUTOR_ID])
            self._display_publish_packages_step(publish_report)
            self._display_publish_metadata_step(publish_report)
            self._display_publish_http_https_step(publish_report)
Exemple #3
0
class PackageSyncRun(object):
    """
    Used to perform a single sync of a Debian repository. This class will
    maintain state relevant to the run and should not be reused across runs.
    """

    def __init__(self, repo, sync_conduit, config, is_cancelled_call):
        self.repo = repo
        self.sync_conduit = sync_conduit
        self.config = config
        self.is_cancelled_call = is_cancelled_call

        self.progress_report = SyncProgressReport(sync_conduit)

        self.dist = model.Distribution(**self.config.get(constants.CONFIG_DIST))

    def perform_sync(self):
        """
        Performs the sync operation according to the configured state of the
        instance. The report to be sent back to Pulp is returned from this
        call. This call will make calls into the conduit's progress update
        as appropriate.

        This call executes serially. No threads are created by this call. It
        will not return until either a step fails or the entire sync is
        completed.

        :return: the report object to return to Pulp from the sync call
        :rtype:  pulp.plugins.model.SyncReport
        """
        _LOG.info('Beginning sync for repository <%s>' % self.repo.id)

        try:
            self._update_dist()
            if len(self.dist.packages) == 0:
                report = self.progress_report.build_final_report()
                return report

            self._import_packages()
        finally:
            # One final progress update before finishing
            self.progress_report.update_progress()

            report = self.progress_report.build_final_report()
            return report

    def _update_dist(self):
        """
        Takes the necessary actions (according to the run configuration) to
        retrieve and parse the repository's resources. This call will return
        either the successfully parsed resources or None if it could not
        be retrieved or parsed. The progress report will be updated with the
        appropriate description of what went wrong in the event of an error,
        so the caller should interpet a None return as an error occuring and
        not continue the sync.

        :return: object representation of the resources
        :rtype:  Repository
        """
        _LOG.info('Beginning resources retrieval for repository <%s>' % self.repo.id)

        self.progress_report.resource_state = STATE_RUNNING
        self.progress_report.update_progress()

        start_time = datetime.now()

        # Retrieve the metadata from the source
        try:
            downloader = self._create_downloader()
            resources = downloader.download_resources(
                self.dist.get_indexes(),
                self.progress_report)
        except Exception, e:
            _LOG.exception('Exception while retrieving resources for repository <%s>' % self.repo.id)
            self.progress_report.state = STATE_FAILED
            self.progress_report.error_message = _('Error downloading resources')
            self.progress_report.exception = e
            self.progress_report.traceback = sys.exc_info()[2]

            end_time = datetime.now()
            duration = end_time - start_time
            self.progress_report.execution_time = duration.seconds

            self.progress_report.update_progress()

            return None

        # Parse the retrieved resoruces documents
        try:
            self.dist.update_from_resources(resources)
        except Exception, e:
            _LOG.exception('Exception parsing resources for repository <%s>' % self.repo.id)
            self.progress_report.state = STATE_FAILED
            self.progress_report.error_message = _('Error parsing repository packages resources document')
            self.progress_report.exception = e
            self.progress_report.traceback = sys.exc_info()[2]

            end_time = datetime.now()
            duration = end_time - start_time
            self.progress_report.execution_time = duration.seconds

            self.progress_report.update_progress()

            return None