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

Python container.ContentContainer类代码示例

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

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



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

示例1: _update_units

 def _update_units(self, request, unit_inventory):
     """
     Update units that have been updated on the parent since
     added or last updated in the child inventory.
     :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.updated_units()
     listener = ContentDownloadListener(self, request)
     for unit, unit_ref in units:
         storage_path = unit[constants.STORAGE_PATH]
         if storage_path:
             self._reset_storage_path(unit)
             unit_url, destination = self._url_and_destination(unit_inventory.base_URL, unit)
             _request = listener.create_request(unit_url, destination, unit, unit_ref)
             download_list.append(_request)
         else:
             unit = unit_ref.fetch()
             self.add_unit(request, unit)
     if not download_list:
         return
     container = ContentContainer()
     request.summary.sources = container.download(
         request.downloader,
         download_list,
         listener)
     request.summary.errors.extend(listener.error_list)
开发者ID:BrnoPCmaniak,项目名称:pulp,代码行数:30,代码来源:strategies.py


示例2: test_download_to_stream

    def test_download_to_stream(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),
                StringIO())
            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),
                StringIO())
            request_list.append(request)
        downloader = LocalFileDownloader(DownloaderConfig())
        listener = Mock()
        container = ContentContainer(path=self.tmp_dir)
        container.threaded = False
        container.refresh = Mock()

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

        # validation
        # unit-world
        for i in range(0, 10):
            request = request_list[i]
            self.assertTrue(request.downloaded)
            self.assertEqual(len(request.errors), 0)
            fp = request.destination
            s = fp.getvalue()
            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)
            fp = request.destination
            s = fp.getvalue()
            self.assertTrue(PRIMARY in s)
        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:alanoe,项目名称:pulp,代码行数:59,代码来源:test_content_sources.py


示例3: test_download

    def test_download(self, fake_load):
        sources = []
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.get_downloader = Mock()
            sources.append(s)

        fake_load.return_value = sources

        request_list = []
        for n in range(6):
            r = Request('T', {}, 'url-%d' % n, 'path-%d' % n)
            r.find_sources = Mock(return_value=sources[n % 3:])
            request_list.append(r)

        collated = [
            {
                sources[0]: ['nectar-1'],
                sources[1]: ['nectar-2', 'nectar-3', 'nectar-4'],
                sources[2]: ['nectar-5', 'nectar-6']
            },
            {}
        ]
        fake_collated = Mock(side_effect=collated)

        fake_listener = Mock()
        canceled = FakeEvent()
        fake_primary = PrimarySource(Mock())

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = fake_collated
        report = container.download(canceled, fake_primary, request_list, fake_listener)

        # validation
        container.refresh.assert_called_with(canceled)

        for r in request_list:
            r.find_sources.assert_called_with(fake_primary, container.sources)

        self.assertEqual(report.total_passes, 1)
        self.assertEqual(report.total_sources, len(sources))
        self.assertEqual(len(report.downloads), 3)
        for source in sources:
            self.assertEqual(report.downloads[source.id].total_succeeded, 0)
            self.assertEqual(report.downloads[source.id].total_failed, 0)

        for source in sources:
            source.get_downloader.assert_called_with()
            downloader = source.get_downloader()
            listener = downloader.event_listener
            self.assertEqual(listener.cancel_event, canceled)
            self.assertEqual(listener.downloader, downloader)
            self.assertEqual(listener.listener, fake_listener)
            downloader.download.assert_called_with(collated[0][source])
开发者ID:aweiteka,项目名称:pulp,代码行数:56,代码来源:test_container.py


示例4: test_purge_orphans

    def test_purge_orphans(self, fake_manager, fake_load):
        fake_load.return_value = {"A": 1, "B": 2, "C": 3}

        # test
        container = ContentContainer("")

        # validation
        container.purge_orphans()

        fake_manager().purge_orphans.assert_called_with(fake_load.return_value.keys())
开发者ID:maxamillion,项目名称:pulp,代码行数:10,代码来源:test_container.py


示例5: test_purge_orphans

    def test_purge_orphans(self, fake_manager, fake_load):
        fake_load.return_value = {'A': 1, 'B': 2, 'C': 3}

        # test
        container = ContentContainer('')

        # validation
        container.purge_orphans()

        fake_manager().purge_orphans.assert_called_with(fake_load.return_value.keys())
开发者ID:aweiteka,项目名称:pulp,代码行数:10,代码来源:test_container.py


示例6: test_download_canceled_after_collated

    def test_download_canceled_after_collated(self, fake_load):
        sources = []
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.get_downloader = Mock()
            sources.append(s)

        fake_load.return_value = sources

        request_list = []
        for n in range(6):
            r = Request('T', {}, 'url-%d' % n, 'path-%d' % n)
            r.find_sources = Mock(return_value=sources[n % 3:])
            request_list.append(r)

        collated = [
            {
                sources[0]: ['nectar-1'],
                sources[1]: ['nectar-2', 'nectar-3', 'nectar-4'],
                sources[2]: ['nectar-5', 'nectar-6']
            },
            {}
        ]
        fake_collated = Mock(side_effect=collated)

        fake_listener = Mock()
        canceled = Mock()
        canceled.isSet.side_effect = [False, True, True]
        fake_primary = PrimarySource(Mock())

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = fake_collated
        report = container.download(canceled, fake_primary, request_list, fake_listener)

        # validation
        container.refresh.assert_called_with(canceled)

        for r in request_list:
            r.find_sources.assert_called_with(fake_primary, container.sources)

        called = 0
        for s in sources:
            if s.get_downloader.called:
                called += 1

        self.assertEqual(called, 1)
        self.assertEqual(report.total_passes, 1)
        self.assertEqual(report.total_sources, len(sources))
        self.assertEqual(len(report.downloads), 1)
        self.assertEqual(report.downloads[sources[2].id].total_succeeded, 0)
        self.assertEqual(report.downloads[sources[2].id].total_failed, 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:53,代码来源:test_container.py


示例7: 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)

        # test
        container.purge_orphans()

        # validation
        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:alanoe,项目名称:pulp,代码行数:16,代码来源:test_content_sources.py


示例8: test_refresh_exception

    def test_refresh_exception(self, mock_refresh):
        container = ContentContainer(path=self.tmp_dir)

        # test
        report = container.refresh(force=True)

        # validation
        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:alanoe,项目名称:pulp,代码行数:16,代码来源:test_content_sources.py


示例9: test_forced_refresh

    def test_forced_refresh(self, fake_manager, fake_load):
        sources = {}
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.refresh = Mock()
            sources[s.id] = s

        fake_manager().has_entries.return_value = True
        fake_load.return_value = sources

        # test
        container = ContentContainer('')
        container.refresh(force=True)

        # validation
        for s in sources.values():
            s.refresh.assert_called_with()
开发者ID:alanoe,项目名称:pulp,代码行数:17,代码来源:test_container.py


示例10: test_refresh_failure

    def test_refresh_failure(self, mock_plugin):
        container = ContentContainer(path=self.tmp_dir)

        # test
        report = container.refresh(force=True)

        # validation
        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:alanoe,项目名称:pulp,代码行数:17,代码来源:test_content_sources.py


示例11: test_download_canceled_before_collated

    def test_download_canceled_before_collated(self, fake_load):
        fake_load.return_value = []
        canceled = FakeEvent()
        canceled.set()

        # test
        container = ContentContainer('')
        container.refresh = Mock()
        container.collated = Mock()
        report = container.download(canceled, None, [], None)

        container.refresh.assert_called_with(canceled)

        self.assertFalse(container.collated.called)
        self.assertEqual(report.total_passes, 0)
        self.assertEqual(report.total_sources, 0)
        self.assertEqual(len(report.downloads), 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:17,代码来源:test_container.py


示例12: test_refresh_canceled

    def test_refresh_canceled(self, fake_load):
        sources = {}
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.refresh = Mock()
            sources[s.id] = s

        fake_load.return_value = sources

        # test
        canceled = FakeEvent()
        canceled.set()
        container = ContentContainer('')
        container.refresh(canceled, force=True)

        # validation
        for s in sources.values():
            self.assertFalse(s.refresh.called)
开发者ID:aweiteka,项目名称:pulp,代码行数:18,代码来源:test_container.py


示例13: test_refresh

    def test_refresh(self, fake_manager, fake_load):
        sources = {}
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.refresh = Mock(return_value=[n])
            s.get_downloader = Mock()
            sources[s.id] = s

        fake_manager().has_entries.return_value = False
        fake_load.return_value = sources

        # test
        container = ContentContainer('')
        report = container.refresh()

        # validation
        for s in sources.values():
            s.refresh.assert_called_with()

        self.assertEqual(sorted(report), [0, 1, 2])
开发者ID:alanoe,项目名称:pulp,代码行数:20,代码来源:test_container.py


示例14: test_threaded_download

    def test_threaded_download(self, fake_load, fake_refresh, fake_primary, fake_batch):
        path = Mock()
        downloader = Mock()
        requests = Mock()
        listener = Mock()

        _batch = Mock()
        _batch.download.return_value = 123
        fake_batch.return_value = _batch

        # test
        container = ContentContainer(path)
        report = container.download(downloader, requests, listener)

        # validation
        fake_load.assert_called_with(path)
        fake_refresh.assert_called_with()
        fake_primary.assert_called_with(downloader)
        fake_batch.assert_called_with(fake_primary(), container, requests, listener)
        _batch.assert_called_with()
        self.assertEqual(report, _batch.return_value)
开发者ID:alanoe,项目名称:pulp,代码行数:21,代码来源:test_container.py


示例15: test_refresh

    def test_refresh(self, mock_plugin):
        container = ContentContainer(path=self.tmp_dir)

        # test
        report = container.refresh(force=True)

        # validation
        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:alanoe,项目名称:pulp,代码行数:21,代码来源:test_content_sources.py


示例16: test_refresh_raised

    def test_refresh_raised(self, fake_manager, fake_load):
        sources = {}
        for n in range(3):
            s = ContentSource('s-%d' % n, {})
            s.refresh = Mock(side_effect=ValueError('must be int'))
            s.get_downloader = Mock()
            sources[s.id] = s

        fake_manager().has_entries.return_value = False
        fake_load.return_value = sources

        # test
        container = ContentContainer('')
        report = container.refresh()

        # validation
        for s in sources.values():
            s.refresh.assert_called_with()

        for r in report:
            r.errors = ['must be int']
开发者ID:alanoe,项目名称:pulp,代码行数:21,代码来源:test_container.py


示例17: test_collated_all_downloaded

    def test_collated_all_downloaded(self):
        request_list = []
        for n in range(10):
            r = Mock()
            r.downloaded = True
            request_list.append(r)

        # test
        collated = ContentContainer.collated(request_list)

        # validation
        self.assertEqual(len(collated), 0)
开发者ID:aweiteka,项目名称:pulp,代码行数:12,代码来源:test_container.py


示例18: _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:AndreaGiardini,项目名称:pulp,代码行数:40,代码来源:strategies.py


示例19: test_download

    def test_download(self, fake_load, fake_refresh, fake_primary, fake_batch):
        path = Mock()
        downloader = Mock()
        requests = Mock()
        listener = Mock()
        canceled = Mock()
        canceled.is_set.return_value = False

        _batch = Mock()
        _batch.download.return_value = 123
        fake_batch.return_value = _batch

        # test
        container = ContentContainer(path)
        report = container.download(canceled, downloader, requests, listener)

        # validation
        fake_load.assert_called_with(path)
        fake_refresh.assert_called_with(canceled)
        fake_primary.assert_called_with(downloader)
        fake_batch.assert_called_with(canceled, fake_primary(), fake_load(), requests, listener)
        fake_batch().download.assert_called_with()
        self.assertEqual(report, _batch.download.return_value)
开发者ID:CUXIDUMDUM,项目名称:pulp,代码行数:23,代码来源:test_container.py


示例20: test_collated

    def test_collated(self):
        source_id = 1
        request_list = []

        # simulated requests
        # 0-8 need to be downloaded and have a next source.
        # 6-7 have no next source.
        # 9-10 are already downloaded.

        for n in range(10):
            r = Mock()
            r.downloaded = n > 8
            r.destination = 'path-%d' % n
            if n < 6:
                r.next_source.return_value = ('s-%d' % source_id, 'url-%d' % n)
            else:
                r.next_source.return_value = None
            request_list.append(r)
            if n % 3 == 0:
                source_id += 1

        # test
        collated = ContentContainer.collated(request_list)

        # validation
        self.assertEqual(len(collated), 3)

        for requests in collated.values():
            for r in requests:
                self.assertTrue(isinstance(r, DownloadRequest))

        self.assertEqual(
            [s.__dict__ for s in collated['s-1']],
            [
                DownloadRequest('url-0', 'path-0', data=request_list[0]).__dict__
            ])
        self.assertEqual(
            [s.__dict__ for s in collated['s-2']],
            [
                DownloadRequest('url-1', 'path-1', data=request_list[1]).__dict__,
                DownloadRequest('url-2', 'path-2', data=request_list[2]).__dict__,
                DownloadRequest('url-3', 'path-3', data=request_list[3]).__dict__
            ])
        self.assertEqual(
            [s.__dict__ for s in collated['s-3']],
            [
                DownloadRequest('url-4', 'path-4', data=request_list[4]).__dict__,
                DownloadRequest('url-5', 'path-5', data=request_list[5]).__dict__,
            ])
开发者ID:aweiteka,项目名称:pulp,代码行数:49,代码来源:test_container.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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