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

Python sources.ContentContainer类代码示例

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

本文整理汇总了Python中pulp.server.content.sources.ContentContainer的典型用法代码示例。如果您正苦于以下问题:Python ContentContainer类的具体用法?Python ContentContainer怎么用?Python ContentContainer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: test_download_cancelled_in_failed

 def test_download_cancelled_in_failed(self, mock_started, mock_cancel):
     request_list = []
     for n in range(0, 5):
         unit_key = {
             'name': 'unit_%d' % n,
             'version': '1.0.%d' % n,
             'release': '1',
             'checksum': str(uuid4())
         }
         request = Request(
             TYPE_ID,
             unit_key,
             'http://unit-city/unit_%d' % n,
             os.path.join(self.downloaded, 'unit_%d' % n))
         request_list.append(request)
     downloader = HTTPThreadedDownloader(DownloaderConfig())
     container = ContentContainer(path=self.tmp_dir)
     container.refresh = Mock()
     event = CancelEvent(2)
     report = container.download(event, downloader, request_list)
     self.assertTrue(mock_started.called)
     self.assertTrue(mock_cancel.called)
     self.assertEqual(report.total_passes, 1)
     self.assertEqual(report.total_sources, 2)
     self.assertEqual(len(report.downloads), 1)
     self.assertEqual(report.downloads[PRIMARY_ID].total_succeeded, 0)
     self.assertEqual(report.downloads[PRIMARY_ID].total_failed, 5)
开发者ID:aweiteka,项目名称:pulp,代码行数:27,代码来源:test_content_sources.py


示例2: test_download_cancelled_during_refreshing

 def test_download_cancelled_during_refreshing(self):
     downloader = LocalFileDownloader(DownloaderConfig())
     container = ContentContainer(path=self.tmp_dir)
     container.collated = Mock()
     event = CancelEvent(1)
     container.download(event, downloader, [])
     self.assertFalse(container.collated.called)
开发者ID:preethit,项目名称:pulp-1,代码行数:7,代码来源:test_content_sources.py


示例3: test_refresh_cancel_in_plugin

 def test_refresh_cancel_in_plugin(self, mock_plugin, *unused):
     container = ContentContainer(path=self.tmp_dir)
     event = CancelEvent(3)
     report = container.refresh(event, force=True)
     plugin = mock_plugin.return_value[0]
     self.assertEqual(plugin.refresh.call_count, 1)
     self.assertEqual(len(report), 1)
开发者ID:aweiteka,项目名称:pulp,代码行数:7,代码来源:test_content_sources.py


示例4: test_download_fail_completely

 def test_download_fail_completely(self):
     request_list = []
     _dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 10)
     shutil.rmtree(_dir)
     _dir = self.populate_content(PRIMARY, 0, 20)
     # primary
     for n in range(0, 10):
         unit_key = {
             'name': 'unit_%d' % n,
             'version': '1.0.%d' % n,
             'release': '1',
             'checksum': str(uuid4())
         }
         request = Request(
             TYPE_ID,
             unit_key,
             'http://redhat.com/%s/unit_%d' % (_dir, n),
             os.path.join(self.downloaded, 'unit_%d' % n))
         request_list.append(request)
     downloader = HTTPThreadedDownloader(DownloaderConfig())
     listener = MockListener()
     container = ContentContainer(path=self.tmp_dir)
     container.refresh = Mock()
     event = Event()
     container.download(event, downloader, request_list, listener)
     # primary
     for i in range(0, len(request_list)):
         request = request_list[i]
         self.assertFalse(request.downloaded)
         self.assertEqual(len(request.errors), 1)
     self.assertEqual(listener.download_started.call_count, len(request_list))
     self.assertEqual(listener.download_succeeded.call_count, 0)
     self.assertEqual(listener.download_failed.call_count, len(request_list))
开发者ID:preethit,项目名称:pulp-1,代码行数:33,代码来源:test_content_sources.py


示例5: test_download

 def test_download(self):
     request_list = []
     _dir, cataloged = self.populate_catalog(ORPHANED, 0, 10)
     _dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 10)
     _dir = self.populate_content(PRIMARY, 0, 20)
     # unit-world
     for n in range(0, 10):
         request = Request(
             cataloged[n].type_id,
             cataloged[n].unit_key,
             'file://%s/unit_%d' % (_dir, n),
             os.path.join(self.downloaded, 'unit_%d' % n))
         request_list.append(request)
     # primary
     for n in range(11, 20):
         unit_key = {
             'name': 'unit_%d' % n,
             'version': '1.0.%d' % n,
             'release': '1',
             'checksum': str(uuid4())
         }
         request = Request(
             TYPE_ID,
             unit_key,
             'file://%s/unit_%d' % (_dir, n),
             os.path.join(self.downloaded, 'unit_%d' % n))
         request_list.append(request)
     downloader = LocalFileDownloader(DownloaderConfig())
     listener = MockListener()
     container = ContentContainer(path=self.tmp_dir)
     container.refresh = Mock()
     event = Event()
     report = container.download(event, downloader, request_list, listener)
     # unit-world
     for i in range(0, 10):
         request = request_list[i]
         self.assertTrue(request.downloaded)
         self.assertEqual(len(request.errors), 0)
         with open(request.destination) as fp:
             s = fp.read()
             self.assertTrue(UNIT_WORLD in s)
     # primary
     for i in range(11, len(request_list)):
         request = request_list[i]
         self.assertTrue(request.downloaded)
         self.assertEqual(len(request.errors), 0)
         with open(request.destination) as fp:
             s = fp.read()
             self.assertTrue(PRIMARY in s)
     self.assertEqual(listener.download_started.call_count, len(request_list))
     self.assertEqual(listener.download_succeeded.call_count, len(request_list))
     self.assertEqual(listener.download_failed.call_count, 0)
     self.assertEqual(report.total_passes, 1)
     self.assertEqual(report.total_sources, 2)
     self.assertEqual(len(report.downloads), 2)
     self.assertEqual(report.downloads[PRIMARY_ID].total_succeeded, 9)
     self.assertEqual(report.downloads[PRIMARY_ID].total_failed, 0)
     self.assertEqual(report.downloads[UNIT_WORLD].total_succeeded, 10)
     self.assertEqual(report.downloads[UNIT_WORLD].total_failed, 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:59,代码来源:test_content_sources.py


示例6: test_download_cancelled_in_download

 def test_download_cancelled_in_download(self):
     container = ContentContainer(path=self.tmp_dir)
     container.collated = Mock()
     event = CancelEvent(1)
     report = container.download(event, None, [])
     self.assertFalse(container.collated.called)
     self.assertEqual(report.total_passes, 0)
     self.assertEqual(report.total_sources, 2)
     self.assertEqual(len(report.downloads), 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:9,代码来源:test_content_sources.py


示例7: test_download_with_errors

    def test_download_with_errors(self):
        request_list = []
        _dir, cataloged = self.populate_catalog(ORPHANED, 0, 10)
        _dir, cataloged = self.populate_catalog(UNDERGROUND, 0, 10)
        _dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 10)
        shutil.rmtree(_dir)
        _dir = self.populate_content(PRIMARY, 0, 20)
        # unit-world
        for n in range(0, 10):
            request = Request(
                cataloged[n].type_id,
                cataloged[n].unit_key,
                "file://%s/unit_%d" % (_dir, n),
                os.path.join(self.downloaded, "unit_%d" % n),
            )
            request_list.append(request)
        # primary
        for n in range(11, 20):
            unit_key = {"name": "unit_%d" % n, "version": "1.0.%d" % n, "release": "1", "checksum": str(uuid4())}
            request = Request(
                TYPE_ID, unit_key, "file://%s/unit_%d" % (_dir, n), os.path.join(self.downloaded, "unit_%d" % n)
            )
            request_list.append(request)
        downloader = LocalFileDownloader(DownloaderConfig())
        listener = Mock()
        container = ContentContainer(path=self.tmp_dir)
        container.refresh = Mock()
        event = Event()

        # test
        report = container.download(event, downloader, request_list, listener)

        # validation
        # unit-world
        for i in range(0, 10):
            request = request_list[i]
            self.assertTrue(request.downloaded, msg="URL: %s" % request.url)
            self.assertEqual(len(request.errors), 1)
            with open(request.destination) as fp:
                s = fp.read()
                self.assertTrue(UNDERGROUND in s)
        # primary
        for i in range(11, len(request_list)):
            request = request_list[i]
            self.assertTrue(request.downloaded, msg="URL: %s" % request.url)
            self.assertEqual(len(request.errors), 0)
            with open(request.destination) as fp:
                s = fp.read()
                self.assertTrue(PRIMARY in s)
        self.assertEqual(report.total_sources, 2)
        self.assertEqual(len(report.downloads), 3)
        self.assertEqual(report.downloads[PRIMARY_ID].total_succeeded, 9)
        self.assertEqual(report.downloads[PRIMARY_ID].total_failed, 0)
        self.assertEqual(report.downloads[UNDERGROUND].total_succeeded, 10)
        self.assertEqual(report.downloads[UNDERGROUND].total_failed, 0)
        self.assertEqual(report.downloads[UNIT_WORLD].total_succeeded, 0)
        self.assertEqual(report.downloads[UNIT_WORLD].total_failed, 10)
开发者ID:nthien,项目名称:pulp,代码行数:57,代码来源:test_content_sources.py


示例8: test_download_cancelled_during_refreshing

 def test_download_cancelled_during_refreshing(self):
     downloader = LocalFileDownloader(DownloaderConfig())
     container = ContentContainer(path=self.tmp_dir)
     container.collated = Mock()
     event = CancelEvent(1)
     report = container.download(event, downloader, [])
     self.assertFalse(container.collated.called)
     self.assertEqual(report.total_passes, 0)
     self.assertEqual(report.total_sources, 2)
     self.assertEqual(len(report.downloads), 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:10,代码来源:test_content_sources.py


示例9: test_purge_orphans

 def test_purge_orphans(self):
     _dir, cataloged = self.populate_catalog(ORPHANED, 0, 10)
     _dir, cataloged = self.populate_catalog(UNDERGROUND, 0, 10)
     _dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 10)
     collection = ContentCatalog.get_collection()
     self.assertEqual(collection.find().count(), 30)
     container = ContentContainer(path=self.tmp_dir)
     container.purge_orphans()
     self.assertEqual(collection.find().count(), 20)
     self.assertEqual(collection.find({'source_id': ORPHANED}).count(), 0)
     self.assertEqual(collection.find({'source_id': UNDERGROUND}).count(), 10)
     self.assertEqual(collection.find({'source_id': UNIT_WORLD}).count(), 10)
开发者ID:aweiteka,项目名称:pulp,代码行数:12,代码来源:test_content_sources.py


示例10: test_refresh_exception

 def test_refresh_exception(self, mock_refresh):
     container = ContentContainer(path=self.tmp_dir)
     event = Event()
     report = container.refresh(event, force=True)
     self.assertEqual(len(report), 2)
     for r in report:
         self.assertFalse(r.succeeded)
         self.assertEqual(r.added_count, 0)
         self.assertEqual(r.deleted_count, 0)
         self.assertEqual(len(r.errors), 1)
     collection = ContentCatalog.get_collection()
     self.assertEqual(mock_refresh.call_count, 2)
     self.assertEqual(collection.find().count(), 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:13,代码来源:test_content_sources.py


示例11: test_refresh_failure

 def test_refresh_failure(self, mock_plugin):
     container = ContentContainer(path=self.tmp_dir)
     event = Event()
     report = container.refresh(event, force=True)
     self.assertEqual(len(report), 5)
     for r in report:
         self.assertFalse(r.succeeded)
         self.assertEqual(r.added_count, 0)
         self.assertEqual(r.deleted_count, 0)
         self.assertEqual(len(r.errors), 1)
     plugin = mock_plugin.return_value[0]
     collection = ContentCatalog.get_collection()
     self.assertEqual(plugin.refresh.call_count, 5)
     self.assertEqual(collection.find().count(), 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:14,代码来源:test_content_sources.py


示例12: test_download_with_errors

    def test_download_with_errors(self):
        request_list = []
        _dir, cataloged = self.populate_catalog(ORPHANED, 0, 1000)
        _dir, cataloged = self.populate_catalog(UNDERGROUND, 0, 1000)
        _dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 1000)
        shutil.rmtree(_dir)
        _dir = self.populate_content(PRIMARY, 0, 2000)
        # unit-world
        for n in range(0, 1000):
            request = Request(
                cataloged[n].type_id,
                cataloged[n].unit_key,
                'file://%s/unit_%d' % (_dir, n),
                os.path.join(self.downloaded, 'unit_%d' % n))
            request_list.append(request)
        # primary
        for n in range(1001, 2000):
            unit_key = {
                'name': 'unit_%d' % n,
                'version': '1.0.%d' % n,
                'release': '1',
                'checksum': str(uuid4())
            }
            request = Request(
                TYPE_ID,
                unit_key,
                'file://%s/unit_%d' % (_dir, n),
                os.path.join(self.downloaded, 'unit_%d' % n))
            request_list.append(request)
        downloader = LocalFileDownloader(DownloaderConfig())
        event = Event()
        threshold = len(request_list) * 0.10  # cancel after 10% started
        listener = TestListener(event, threshold)
        container = ContentContainer(path=self.tmp_dir)
        container.refresh = Mock()

        # test
        report = container.download(event, downloader, request_list, listener)

        # validation
        self.assertEqual(report.total_sources, 2)
        self.assertEqual(len(report.downloads), 2)
        self.assertTrue(0 < report.downloads[UNDERGROUND].total_succeeded < 500)
        self.assertEqual(report.downloads[UNDERGROUND].total_failed, 0)
        self.assertEqual(report.downloads[UNIT_WORLD].total_succeeded, 0)
        self.assertTrue(0 < report.downloads[UNIT_WORLD].total_failed < 1000)
开发者ID:skarmark,项目名称:pulp,代码行数:46,代码来源:test_content_sources.py


示例13: test_refresh

 def test_refresh(self, mock_plugin):
     container = ContentContainer(path=self.tmp_dir)
     event = Event()
     report = container.refresh(event, force=True)
     plugin = mock_plugin.return_value[0]
     self.assertEqual(plugin.refresh.call_count, 5)
     self.assertEqual(len(report), 5)
     for r in report:
         self.assertTrue(r.succeeded)
         self.assertEqual(r.added_count, 100)
         self.assertEqual(r.deleted_count, 0)
     calls = iter(plugin.refresh.call_args_list)
     for source in ContentSource.load_all(self.tmp_dir).values():
         for url in source.urls:
             args = calls.next()[0]
             self.assertTrue(isinstance(args[0], CatalogerConduit))
             self.assertEqual(args[1], source.descriptor)
             self.assertEqual(args[2], url)
开发者ID:aweiteka,项目名称:pulp,代码行数:18,代码来源:test_content_sources.py


示例14: _add_units

 def _add_units(self, request, unit_inventory):
     """
     Determine the list of units contained in the parent inventory
     but are not contained in the child inventory and add them.
     For each unit, this is performed in the following steps:
       1. Download the file (if defined) associated with the unit.
       2. Add the unit to the child inventory.
       3. Associate the unit to the repository.
     The unit is added only:
       1. If no file is associated with unit.
       2. The file associated with the unit is successfully downloaded.
     For units with files, the unit is added to the inventory as part of the
     unit download manager callback.
     :param request: A synchronization request.
     :type request: SyncRequest
     :param unit_inventory: The inventory of both parent and child content units.
     :type unit_inventory: UnitInventory
     """
     download_list = []
     units = unit_inventory.units_on_parent_only()
     request.progress.begin_adding_units(len(units))
     listener = ContentDownloadListener(self, request)
     for unit, unit_ref in units:
         if request.cancelled():
             return
         self._reset_storage_path(unit)
         if not self._needs_download(unit):
             # unit has no file associated
             self.add_unit(request, unit_ref.fetch())
             continue
         unit_path, destination = self._path_and_destination(unit)
         unit_URL = pathlib.url_join(unit_inventory.base_URL, unit_path)
         _request = listener.create_request(unit_URL, destination, unit, unit_ref)
         download_list.append(_request)
     if request.cancelled():
         return
     container = ContentContainer()
     request.summary.sources = \
         container.download(request.cancel_event, request.downloader, download_list, listener)
     request.summary.errors.extend(listener.error_list)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:40,代码来源:strategies.py


示例15: test_download_cancelled_in_started

 def test_download_cancelled_in_started(self, mock_cancel):
     request_list = []
     _dir = self.populate_content(PRIMARY, 0, 5)
     for n in range(0, 5):
         unit_key = {
             'name': 'unit_%d' % n,
             'version': '1.0.%d' % n,
             'release': '1',
             'checksum': str(uuid4())
         }
         request = Request(
             TYPE_ID,
             unit_key,
             'file://%s/unit_%d' % (_dir, n),
             os.path.join(self.downloaded, 'unit_%d' % n))
         request_list.append(request)
     downloader = LocalFileDownloader(DownloaderConfig())
     container = ContentContainer(path=self.tmp_dir)
     container.refresh = Mock()
     event = CancelEvent(2)
     container.download(event, downloader, request_list)
     self.assertTrue(mock_cancel.called)
开发者ID:preethit,项目名称:pulp-1,代码行数:22,代码来源:test_content_sources.py


示例16: test_download

    def test_download(self):
        request_list = []
        _dir, cataloged = self.populate_catalog(ORPHANED, 0, 1000)
        _dir, cataloged = self.populate_catalog(UNIT_WORLD, 0, 1000)
        _dir = self.populate_content(PRIMARY, 0, 2000)
        # unit-world
        for n in range(0, 1000):
            request = Request(
                cataloged[n].type_id,
                cataloged[n].unit_key,
                "file://%s/unit_%d" % (_dir, n),
                os.path.join(self.downloaded, "unit_%d" % n),
            )
            request_list.append(request)
        # primary
        for n in range(1001, 2000):
            unit_key = {"name": "unit_%d" % n, "version": "1.0.%d" % n, "release": "1", "checksum": str(uuid4())}
            request = Request(
                TYPE_ID, unit_key, "file://%s/unit_%d" % (_dir, n), os.path.join(self.downloaded, "unit_%d" % n)
            )
            request_list.append(request)
        event = Event()
        threshold = len(request_list) * 0.80  # cancel after 80% started
        downloader = LocalFileDownloader(DownloaderConfig())
        listener = TestListener(event, threshold)
        container = ContentContainer(path=self.tmp_dir)
        container.refresh = Mock()

        # test
        report = container.download(event, downloader, request_list, listener)

        # validation
        self.assertEqual(report.total_sources, 2)
        self.assertEqual(len(report.downloads), 2)
        self.assertTrue(0 < report.downloads[PRIMARY_ID].total_succeeded < 999)
        self.assertEqual(report.downloads[PRIMARY_ID].total_failed, 0)
        self.assertEqual(report.downloads[UNIT_WORLD].total_succeeded, 1000)
        self.assertEqual(report.downloads[UNIT_WORLD].total_failed, 0)
开发者ID:nthien,项目名称:pulp,代码行数:38,代码来源:test_content_sources.py


示例17: __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:asmacdo,项目名称:pulp_rpm,代码行数:18,代码来源:alternate.py


示例18: Packages

class Packages(object):
    """
    Package downloader.
    :ivar base_url: The repository base url.
    :type base_url: str
    :ivar units: An iterable of units to download.
    :type units: iterable
    :ivar dst_dir: The absolute path to where the packages are to be downloaded.
    :type dst_dir: str
    :ivar listener: A nectar listener.
    :type listener: nectar.listener.DownloadListener
    :ivar primary: The primary nectar downloader.
    :type primary: nectar.downloaders.base.Downloader
    :ivar container: A content container.
    :type container: ContentContainer
    :ivar canceled: An event that signals the running download has been canceled.
    :type canceled: threading.Event
    """

    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()

    @property
    def downloader(self):
        """
        Provided only for API comparability.
        :return: self
        """
        return self

    def get_requests(self):
        """
        Get requests for the units requested to be downloaded.
        :return: An iterable of: Request
        :rtype: iterable
        """
        for unit in self.units:
            if unit.metadata.get('base_url'):
                url = urljoin(unit.metadata.get('base_url'), unit.download_path)
            else:
                url = urljoin(self.base_url, unit.download_path)
            file_name = os.path.basename(unit.relative_path)
            destination = os.path.join(self.dst_dir, file_name)
            request = Request(
                type_id=unit.TYPE,
                unit_key=unit.unit_key,
                url=url,
                destination=destination)
            request.data = unit
            yield request

    def download_packages(self):
        """
        Download packages using alternate content source container.
        """
        report = self.container.download(
            self.canceled, self.primary, self.get_requests(), self.listener)
        log.info(CONTAINER_REPORT, dict(r=report.dict(), u=self.base_url))

    def cancel(self):
        """
        Cancel a running download.
        """
        self.canceled.set()
开发者ID:asmacdo,项目名称:pulp_rpm,代码行数:80,代码来源:alternate.py


示例19: test_download_cancelled_in_download

 def test_download_cancelled_in_download(self):
     container = ContentContainer(path=self.tmp_dir)
     container.collated = Mock()
     event = CancelEvent(1)
     container.download(event, None, [])
     self.assertFalse(container.collated.called)
开发者ID:preethit,项目名称:pulp-1,代码行数:6,代码来源:test_content_sources.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python container.ContentContainer类代码示例发布时间:2022-05-25
下一篇:
Python config.set函数代码示例发布时间: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