• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python nectar_factory.create_downloader函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulp_rpm.plugins.importers.yum.repomd.nectar_factory.create_downloader函数的典型用法代码示例。如果您正苦于以下问题:Python create_downloader函数的具体用法?Python create_downloader怎么用?Python create_downloader使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了create_downloader函数的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: get_treefile

def get_treefile(feed, tmp_dir, nectar_config):
    """
    Download the treefile and return its full path on disk, or None if not found

    :param feed:            URL to the repository
    :type  feed:            str
    :param tmp_dir:         full path to the temporary directory being used
    :type  tmp_dir:         str
    :param nectar_config:   download config to be used by nectar
    :type  nectar_config:   nectar.config.DownloaderConfig

    :return:        full path to treefile on disk, or None if not found
    :rtype:         str or NoneType
    """
    for filename in constants.TREE_INFO_LIST:
        path = os.path.join(tmp_dir, filename)
        url = os.path.join(feed, filename)
        request = DownloadRequest(url, path)
        listener = AggregatingEventListener()
        downloader = nectar_factory.create_downloader(feed, nectar_config, listener)
        downloader.download([request])
        if len(listener.succeeded_reports) == 1:
            # bz 1095829
            strip_treeinfo_repomd(path)
            return path
开发者ID:FlorianHeigl,项目名称:pulp_rpm,代码行数:25,代码来源:treeinfo.py


示例2: __init__

    def __init__(self, repo_url, dst_dir, nectar_config, url_modify=None):
        """
        :param repo_url:        URL for the base of a yum repository
        :type  repo_url:        basestring
        :param dst_dir:         full path to a destination to which files
                                should be downloaded
        :type  dst_dir:         basestring
        :param nectar_config:   download config for nectar
        :type  nectar_config:   nectar.config.DownloaderConfig
        :param url_modify:      Optional URL modifier
        :type  url_modify:      pulp_rpm.plugins.importers.yum.utils.RepoURLModifier
        """
        super(MetadataFiles, self).__init__()

        self._url_modify = url_modify or utils.RepoURLModifier()
        self.repo_url = self._url_modify(repo_url)
        self.dst_dir = dst_dir
        self.event_listener = AggregatingEventListener()

        self.downloader = nectar_factory.create_downloader(self.repo_url, nectar_config,
                                                           self.event_listener)

        self.revision = None
        self.metadata = {}
        self.dbs = {}
        self.rpm_count = None
开发者ID:ATIX-AG,项目名称:pulp_rpm,代码行数:26,代码来源:metadata.py


示例3: get_distribution_file

def get_distribution_file(feed, tmp_dir, nectar_config):
    """
    Download the pulp_distribution.xml and return its full path on disk, or None if not found

    :param feed:            URL to the repository
    :type  feed:            str
    :param tmp_dir:         full path to the temporary directory being used
    :type  tmp_dir:         str
    :param nectar_config:   download config to be used by nectar
    :type  nectar_config:   nectar.config.DownloaderConfig

    :return:        full path to distribution file on disk, or None if not found
    :rtype:         str or NoneType
    """
    filename = constants.DISTRIBUTION_XML

    path = os.path.join(tmp_dir, filename)
    url = os.path.join(feed, filename)
    request = DownloadRequest(url, path)
    listener = AggregatingEventListener()
    downloader = nectar_factory.create_downloader(feed, nectar_config, listener)
    downloader.download([request])
    if len(listener.succeeded_reports) == 1:
        return path

    return None
开发者ID:FlorianHeigl,项目名称:pulp_rpm,代码行数:26,代码来源:treeinfo.py


示例4: download_files

    def download_files(self, tmp_dir, files):
        """
        Download distribution files.

        :param tmp_dir: The absolute to where the downloaded files.
        :type tmp_dir: str
        :param files: List of distribution dictionary files.
        :type files: list
        :return: generator of: (destination, location)
            The *destination* is the absolute path to the downloaded file.
            The *location* is the relative path within the tmp_dir.
        :rtype: generator
        :raise DownloadFailed: if any of the downloads fail.
        """
        listener = DistFileListener(self)
        self.progress_report.set_initial_values(len(files))
        downloader = nectar_factory.create_downloader(self.feed, self.nectar_config, listener)
        requests = (self.file_to_download_request(f, tmp_dir) for f in files)
        downloader.download(requests)
        if len(listener.failed_reports):
            _logger.error(_('some distro file downloads failed'))
            self.progress_report['state'] = constants.STATE_FAILED
            self.progress_report['error_details'] = [
                (fail.url, fail.error_report) for fail in listener.failed_reports
            ]
            raise DownloadFailed()
        for report in listener.succeeded_reports:
            location = os.path.relpath(report.destination, tmp_dir)
            yield report.destination, location
开发者ID:roysjosh,项目名称:pulp_rpm,代码行数:29,代码来源:treeinfo.py


示例5: _parse_as_mirrorlist

    def _parse_as_mirrorlist(self, feed):
        """
        Treats the provided feed as mirrorlist. Parses its content and extracts
        urls to sync.

        :param feed: feed that should be treated as mirrorlist
        :type:       str

        :return:    list the URLs received from the mirrorlist
        :rtype:     list
        """
        url_file = StringIO()
        downloader = nectar_factory.create_downloader(feed, self.nectar_config)
        request = DownloadRequest(feed, url_file)
        downloader.download_one(request)
        url_file.seek(0)
        url_parse = url_file.read().split('\n')
        repo_url = []
        # Due to the fact, that format of mirrorlist can be different, this regex
        # matches the cases when the url is not commented out and does not have any
        # punctuation characters in front.
        pattern = re.compile("(^|^[\w\s=]+\s)((http(s)?)://.*)")
        for line in url_parse:
            for match in re.finditer(pattern, line):
                repo_url.append(match.group(2))
        random.shuffle(repo_url)
        return repo_url
开发者ID:dokuhebi,项目名称:pulp_rpm,代码行数:27,代码来源:sync.py


示例6: __init__

    def __init__(self, repo_url, nectar_config, package_model_iterator, dst_dir,
                 event_listener=None):
        self.repo_url = repo_url
        self.package_model_iterator = package_model_iterator
        self.dst_dir = dst_dir

        self.downloader = nectar_factory.create_downloader(repo_url, nectar_config,
                                                           event_listener)
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:8,代码来源:packages.py


示例7: sync

def sync(sync_conduit, feed, working_dir, nectar_config, report, progress_callback):
    """
    Look for a distribution in the target repo and sync it if found

    :param sync_conduit:        conduit provided by the platform
    :type  sync_conduit:        pulp.plugins.conduits.repo_sync.RepoSyncConduit
    :param feed:                URL of the yum repo being sync'd
    :type  feed:                basestring
    :param working_dir:         full path to the directory to which files
                                should be downloaded
    :type  working_dir:         basestring
    :param nectar_config:       download config to be used by nectar
    :type  nectar_config:       nectar.config.DownloaderConfig
    :param report:              progress report object
    :type  report:              pulp_rpm.plugins.importers.yum.report.DistributionReport
    :param progress_callback:   function that takes no arguments but induces
                                the current progress report to be sent.
    """
    # this temporary dir will hopefully be moved to the unit's storage path
    # if all downloads go well. If not, it will be deleted below, ensuring a
    # complete cleanup
    tmp_dir = tempfile.mkdtemp(dir=working_dir)
    try:
        treefile_path = get_treefile(feed, tmp_dir, nectar_config)
        if not treefile_path:
            _LOGGER.debug('no treefile found')
            report['state'] = constants.STATE_COMPLETE
            return

        try:
            model, files = parse_treefile(treefile_path)
        except ValueError:
            _LOGGER.error('could not parse treefile')
            report['state'] = constants.STATE_FAILED
            return

        report.set_initial_values(len(files))
        listener = DistroFileListener(report, progress_callback)
        downloader = nectar_factory.create_downloader(feed, nectar_config, listener)
        _LOGGER.debug('downloading distribution files')
        downloader.download(file_to_download_request(f, feed, tmp_dir) for f in files)
        if len(listener.failed_reports) == 0:
            unit = sync_conduit.init_unit(ids.TYPE_ID_DISTRO, model.unit_key, model.metadata, model.relative_path)
            model.process_download_reports(listener.succeeded_reports)
            # remove pre-existing dir
            shutil.rmtree(unit.storage_path, ignore_errors=True)
            shutil.move(tmp_dir, unit.storage_path)
            # mkdtemp is very paranoid, so we'll change to more sensible perms
            os.chmod(unit.storage_path, 0o775)
            sync_conduit.save_unit(unit)
        else:
            _LOGGER.error('some distro file downloads failed')
            report['state'] = constants.STATE_FAILED
            report['error_details'] = [(fail.url, fail.error_report) for fail in listener.failed_reports]
            return
        report['state'] = constants.STATE_COMPLETE
    finally:
        shutil.rmtree(tmp_dir, ignore_errors=True)
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:58,代码来源:treeinfo.py


示例8: get_downloader

 def get_downloader(self, conduit, config, url):
     """
     Get object suitable for downloading content published
     in the content catalog by a content source.
     :param conduit: Access to pulp platform API.
     :type conduit: pulp.server.plugins.conduits.cataloger.CatalogerConduit
     :param config: The content source configuration.
     :type config: dict
     :param url: The URL for the content source.
     :type url: str
     :return: A configured downloader.
     :rtype: nectar.downloaders.base.Downloader
     """
     return nectar_factory.create_downloader(url, self.nectar_config(config))
开发者ID:asmacdo,项目名称:pulp_rpm,代码行数:14,代码来源:yum.py


示例9: __init__

 def __init__(self, base_url, nectar_conf, units, dst_dir, listener):
     """
     :param base_url: The repository base url.
     :type base_url: str
     :param units: An iterable of units to download.
     :type units: iterable
     :param dst_dir: The absolute path to where the packages are to be downloaded.
     :type dst_dir: str
     :param listener: A nectar listener.
     :type listener: nectar.listener.DownloadListener
     """
     self.base_url = base_url
     self.units = units
     self.dst_dir = dst_dir
     self.listener = ContainerListener(listener)
     self.primary = create_downloader(base_url, nectar_conf)
     self.container = ContentContainer()
     self.canceled = Event()
开发者ID:AndreaGiardini,项目名称:pulp_rpm,代码行数:18,代码来源:alternate.py


示例10: get_distribution_file

    def get_distribution_file(self, tmp_dir):
        """
        Download the pulp_distribution.xml and return its full path on disk, or None if not found

        :param tmp_dir: The absolute path to the temporary directory
        :type tmp_dir: str
        :return: The absolute path to distribution file on disk, or None if not found
        :rtype: str or None
        """
        filename = constants.DISTRIBUTION_XML
        path = os.path.join(tmp_dir, filename)
        url = os.path.join(self.feed, filename)
        request = DownloadRequest(url, path)
        listener = AggregatingEventListener()
        downloader = nectar_factory.create_downloader(self.feed, self.nectar_config, listener)
        downloader.download([request])
        if len(listener.succeeded_reports) == 1:
            return path
        return None
开发者ID:roysjosh,项目名称:pulp_rpm,代码行数:19,代码来源:treeinfo.py


示例11: get_treefile

    def get_treefile(self, tmp_dir):
        """
        Download the treefile and return its full path on disk, or None if not found

        :param tmp_dir: The absolute path to the temporary directory
        :type tmp_dir: str
        :return: The absolute path to treefile on disk, or None if not found
        :rtype: str or None
        """
        for filename in constants.TREE_INFO_LIST:
            path = os.path.join(tmp_dir, filename)
            url = os.path.join(self.feed, filename)
            request = DownloadRequest(url, path)
            listener = AggregatingEventListener()
            downloader = nectar_factory.create_downloader(self.feed, self.nectar_config, listener)
            downloader.download([request])
            if len(listener.succeeded_reports) == 1:
                # bz 1095829
                self.strip_treeinfo_repomd(path)
                return path
开发者ID:roysjosh,项目名称:pulp_rpm,代码行数:20,代码来源:treeinfo.py


示例12: __init__

    def __init__(self, repo_url, dst_dir, nectar_config):
        """
        :param repo_url:        URL for the base of a yum repository
        :type  repo_url:        basestring
        :param dst_dir:         full path to a destination to which files
                                should be downloaded
        :type  dst_dir:         basestring
        :param nectar_config:   download config for nectar
        :type  nectar_config:   nectar.config.DownloaderConfig
        """
        super(MetadataFiles, self).__init__()
        self.repo_url = repo_url
        self.dst_dir = dst_dir
        self.event_listener = AggregatingEventListener()

        self.downloader = nectar_factory.create_downloader(repo_url, nectar_config, self.event_listener)

        self.revision = None
        self.metadata = {}
        self.dbs = {}
开发者ID:pombredanne,项目名称:rcm-pulp-rpm,代码行数:20,代码来源:metadata.py


示例13: __init__

 def __init__(self, base_url, nectar_conf, units, dst_dir, listener, url_modify=None):
     """
     :param base_url: The repository base url.
     :type base_url: str
     :param units: An iterable of units to download.
     :type units: iterable
     :param dst_dir: The absolute path to where the packages are to be downloaded.
     :type dst_dir: str
     :param listener: A nectar listener.
     :type listener: nectar.listener.DownloadListener
     :param url_modify: Optional URL modifier
     :type url_modify: pulp_rpm.plugins.importers.yum.utils.RepoURLModifier
     """
     self.base_url = base_url
     self.units = units
     self.dst_dir = dst_dir
     self.listener = ContainerListener(listener)
     self.primary = create_downloader(base_url, nectar_conf)
     self.container = ContentContainer()
     self.url_modify = url_modify or RepoURLModifier()
开发者ID:goosemania,项目名称:pulp_rpm,代码行数:20,代码来源:alternate.py


示例14: sync

def sync(sync_conduit, feed, working_dir, nectar_config, report, progress_callback):
    """
    Look for a distribution in the target repo and sync it if found

    :param sync_conduit:        conduit provided by the platform
    :type  sync_conduit:        pulp.plugins.conduits.repo_sync.RepoSyncConduit
    :param feed:                URL of the yum repo being sync'd
    :type  feed:                basestring
    :param working_dir:         full path to the directory to which files
                                should be downloaded
    :type  working_dir:         basestring
    :param nectar_config:       download config to be used by nectar
    :type  nectar_config:       nectar.config.DownloaderConfig
    :param report:              progress report object
    :type  report:              pulp_rpm.plugins.importers.yum.report.DistributionReport
    :param progress_callback:   function that takes no arguments but induces
                                the current progress report to be sent.
    """
    # this temporary dir will hopefully be moved to the unit's storage path
    # if all downloads go well. If not, it will be deleted below, ensuring a
    # complete cleanup
    tmp_dir = tempfile.mkdtemp(dir=working_dir)
    try:
        treefile_path = get_treefile(feed, tmp_dir, nectar_config)
        if not treefile_path:
            _LOGGER.debug('no treefile found')
            return

        try:
            model, files = parse_treefile(treefile_path)
        except ValueError:
            _LOGGER.error('could not parse treefile')
            report['state'] = constants.STATE_FAILED
            return

        distribution_type_criteria = UnitAssociationCriteria(type_ids=[ids.TYPE_ID_DISTRO])
        existing_units = sync_conduit.get_units(criteria=distribution_type_criteria)

        # skip this whole process if the upstream treeinfo file hasn't changed
        if len(existing_units) == 1 and existing_distribution_is_current(existing_units[0], model):
            _LOGGER.debug('upstream distribution unchanged; skipping')
            return

        # Get any errors
        dist_files = process_distribution(feed, tmp_dir, nectar_config, model, report)
        files.extend(dist_files)

        report.set_initial_values(len(files))
        listener = DistroFileListener(report, progress_callback)
        downloader = nectar_factory.create_downloader(feed, nectar_config, listener)
        _LOGGER.debug('downloading distribution files')
        downloader.download(file_to_download_request(f, feed, tmp_dir) for f in files)
        if len(listener.failed_reports) == 0:
            unit = sync_conduit.init_unit(ids.TYPE_ID_DISTRO, model.unit_key, model.metadata,
                                          model.relative_path)
            model.process_download_reports(listener.succeeded_reports)
            # remove pre-existing dir
            shutil.rmtree(unit.storage_path, ignore_errors=True)
            pulp_copytree(tmp_dir, unit.storage_path)
            # mkdtemp is very paranoid, so we'll change to more sensible perms
            os.chmod(unit.storage_path, 0o775)
            sync_conduit.save_unit(unit)
            # find any old distribution units and remove them. See BZ #1150714
            for existing_unit in existing_units:
                if existing_unit != unit:
                    _LOGGER.info("Removing out-of-date distribution unit %s for repo %s" %
                                 (existing_unit.unit_key, sync_conduit.repo_id))
                    sync_conduit.remove_unit(existing_unit)
        else:
            _LOGGER.error('some distro file downloads failed')
            report['state'] = constants.STATE_FAILED
            report['error_details'] = [(fail.url, fail.error_report) for fail in
                                       listener.failed_reports]
            return
    finally:
        shutil.rmtree(tmp_dir, ignore_errors=True)
开发者ID:FlorianHeigl,项目名称:pulp_rpm,代码行数:76,代码来源:treeinfo.py


示例15: test_file_url

 def test_file_url(self):
     downloader = nectar_factory.create_downloader('file:///foo', self.mock_config,
                                                   self.mock_event_listener)
     self.assertTrue(isinstance(downloader, HTTPCurlDownloader))
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:4,代码来源:test_nectar_factory.py


示例16: sync

def sync(repo, sync_conduit, feed, working_dir, nectar_config, report, progress_callback):
    """
    Look for a distribution in the target repo and sync it if found

    :param repo: The repository that is the target of the sync
    :type repo: pulp.server.db.model.Repository
    :param sync_conduit:        conduit provided by the platform
    :type  sync_conduit:        pulp.plugins.conduits.repo_sync.RepoSyncConduit
    :param feed:                URL of the yum repo being sync'd
    :type  feed:                basestring
    :param working_dir:         full path to the directory to which files
                                should be downloaded
    :type  working_dir:         basestring
    :param nectar_config:       download config to be used by nectar
    :type  nectar_config:       nectar.config.DownloaderConfig
    :param report:              progress report object
    :type  report:              pulp_rpm.plugins.importers.yum.report.DistributionReport
    :param progress_callback:   function that takes no arguments but induces
                                the current progress report to be sent.
    """
    tmp_dir = tempfile.mkdtemp(dir=working_dir)
    try:
        treefile_path = get_treefile(feed, tmp_dir, nectar_config)
        if not treefile_path:
            _LOGGER.debug('no treefile found')
            return

        try:
            model, files = parse_treefile(treefile_path)
        except ValueError:
            _LOGGER.error('could not parse treefile')
            report['state'] = constants.STATE_FAILED
            return

        existing_units = repo_controller.find_repo_content_units(
            repo, repo_content_unit_q=mongoengine.Q(unit_type_id=ids.TYPE_ID_DISTRO),
            yield_content_unit=True)
        existing_units = list(existing_units)

        # skip this whole process if the upstream treeinfo file hasn't changed
        if len(existing_units) == 1 and existing_distribution_is_current(existing_units[0], model):
            _LOGGER.debug('upstream distribution unchanged; skipping')
            return

        # Get any errors
        dist_files = process_distribution(feed, tmp_dir, nectar_config, model, report)
        files.extend(dist_files)

        report.set_initial_values(len(files))
        listener = DistroFileListener(report, progress_callback)
        downloader = nectar_factory.create_downloader(feed, nectar_config, listener)
        _LOGGER.debug('downloading distribution files')
        downloader.download(file_to_download_request(f, feed, tmp_dir) for f in files)
        if len(listener.failed_reports) == 0:
            model.set_content(tmp_dir)
            model.save()
            # The save sets the content path, which is needed to generate the download_reports
            # Long term this should be done by a serializer
            model.process_download_reports(listener.succeeded_reports)
            model.save()

            repo_controller.associate_single_unit(repo, model)

            # find any old distribution units and remove them. See BZ #1150714
            for existing_unit in existing_units:
                if existing_unit != model:
                    _LOGGER.info("Removing out-of-date distribution unit %s for repo %s" %
                                 (existing_unit.unit_key, sync_conduit.repo_id))
                    platform_models.RepositoryContentUnit.objects(
                        repo_id=sync_conduit.repo_id,
                        unit_type_id=models.Distribution._content_type_id.default,
                        unit_id=existing_unit.id).delete()
        else:
            _LOGGER.error('some distro file downloads failed')
            report['state'] = constants.STATE_FAILED
            report['error_details'] = [(fail.url, fail.error_report) for fail in
                                       listener.failed_reports]
            return
    finally:
        shutil.rmtree(tmp_dir, ignore_errors=True)
开发者ID:dkliban,项目名称:pulp_rpm,代码行数:80,代码来源:treeinfo.py


示例17: test_https_url

 def test_https_url(self):
     downloader = nectar_factory.create_downloader('https://foo', self.mock_config,
                                                   self.mock_event_listener)
     self.assertTrue(isinstance(downloader, HTTPThreadedDownloader))
开发者ID:bechtoldt,项目名称:pulp_rpm,代码行数:4,代码来源:test_nectar_factory.py



注:本文中的pulp_rpm.plugins.importers.yum.repomd.nectar_factory.create_downloader函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python packages.package_list_generator函数代码示例发布时间:2022-05-25
下一篇:
Python configuration.validate函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap