Esempio n. 1
0
    def download_drpms(self, metadata_files, drpms_to_download, url):
        """
        Actually download the requested DRPMs. This method iterates over
        the appropriate metadata file and downloads those items which are present
        in the corresponding set. It also checks for the DRPMs which exist
        in other repositories before downloading them. If they are already downloaded,
        we skip the download and just associate them to the given repository.

        Multiple options for deltainfo files depending on the distribution
        so we have to go through all of them to get all the DRPMs

        :param metadata_files:      populated instance of MetadataFiles
        :type  metadata_files:      pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
        :param drpms_to_download:   set of DRPM.NAMEDTUPLEs
        :type  drpms_to_download:   set
        :param url: current URL we should sync
        :type: str
        """
        event_listener = RPMListener(self, metadata_files)

        for presto_file_name in presto.METADATA_FILE_NAMES:
            presto_file_handle = metadata_files.get_metadata_file_handle(presto_file_name)
            if presto_file_handle:
                try:
                    package_model_generator = packages.package_list_generator(
                        presto_file_handle,
                        presto.PACKAGE_TAG,
                        presto.process_package_element)

                    units_to_download = self._filtered_unit_generator(package_model_generator,
                                                                      drpms_to_download)

                    if self.download_deferred:
                        catalog = PackageCatalog(self.conduit.importer_object_id, url)
                        for unit in units_to_download:
                            unit.downloaded = False
                            unit = self.add_drpm_unit(metadata_files, unit)
                            catalog.add(unit)
                        continue

                    download_wrapper = packages.Packages(
                        url,
                        self.nectar_config,
                        units_to_download,
                        self.tmp_dir,
                        event_listener,
                        self._url_modify)

                    self.downloader = download_wrapper.downloader
                    _logger.info(_('Downloading %(num)s DRPMs.') % {'num': len(drpms_to_download)})
                    download_wrapper.download_packages()
                    self.downloader = None
                finally:
                    presto_file_handle.close()
Esempio n. 2
0
    def download_rpms(self, metadata_files, rpms_to_download, url):
        """
        Actually download the requested RPMs. This method iterates over
        the appropriate metadata file and downloads those items which are present
        in the corresponding set. It also checks for the RPMs which exist
        in other repositories before downloading them. If they are already downloaded,
        we skip the download and just associate them to the given repository.

        :param metadata_files:      populated instance of MetadataFiles
        :type  metadata_files:      pulp_rpm.plugins.importers.yum.repomd.metadata.MetadataFiles
        :param rpms_to_download:    set of RPM.NAMEDTUPLEs
        :type  rpms_to_download:    set
        :param url: current URL we should sync
        :type: str
        """
        event_listener = RPMListener(self, metadata_files)
        primary_file_handle = metadata_files.get_metadata_file_handle(
            primary.METADATA_FILE_NAME)

        try:
            package_model_generator = packages.package_list_generator(
                primary_file_handle, primary.PACKAGE_TAG,
                primary.process_package_element)

            units_to_download = self._filtered_unit_generator(
                package_model_generator, rpms_to_download)

            # Wrapped in a generator that adds entries to
            # the deferred (Lazy) catalog.
            units_to_download = self.catalog_generator(url, units_to_download)

            if self.download_deferred:
                for unit in units_to_download:
                    unit.downloaded = False
                    self.add_rpm_unit(metadata_files, unit)
                return

            download_wrapper = alternate.Packages(url, self.nectar_config,
                                                  units_to_download,
                                                  self.tmp_dir, event_listener,
                                                  self._url_modify)

            # allow the downloader to be accessed by the cancel method if necessary
            self.downloader = download_wrapper.downloader
            _logger.info(
                _('Downloading %(num)s RPMs.') %
                {'num': len(rpms_to_download)})
            download_wrapper.download_packages()
            self.downloader = None
        finally:
            primary_file_handle.close()