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

Python public_storage.exists函数代码示例

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

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



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

示例1: image_status

def image_status(request, addon_id, addon, icon_size=64):
    # Default icon needs no checking.
    if not addon.icon_type or addon.icon_type.split("/")[0] == "icon":
        icons = True
    else:
        icons = public_storage.exists(os.path.join(addon.get_icon_dir(), "%s-%s.png" % (addon.id, icon_size)))
    previews = all(public_storage.exists(p.thumbnail_path) for p in addon.get_previews())
    return {"overall": icons and previews, "icons": icons, "previews": previews}
开发者ID:pkdevboxy,项目名称:zamboni,代码行数:8,代码来源:views.py


示例2: check_delete

 def check_delete(self, file_, filename):
     """Test that when the File object is deleted, it is removed from the
     filesystem."""
     try:
         with public_storage.open(filename, 'w') as f:
             f.write('sample data\n')
         assert public_storage.exists(filename)
         file_.delete()
         assert not public_storage.exists(filename)
     finally:
         if public_storage.exists(filename):
             public_storage.delete(filename)
开发者ID:Witia1,项目名称:zamboni,代码行数:12,代码来源:test_models.py


示例3: image_status

def image_status(request, addon_id, addon, icon_size=64):
    # Default icon needs no checking.
    if not addon.icon_type or addon.icon_type.split('/')[0] == 'icon':
        icons = True
    else:
        icons = public_storage.exists(
            os.path.join(addon.get_icon_dir(), '%s-%s.png' % (
                addon.id, icon_size)))
    previews = all(public_storage.exists(p.thumbnail_path)
                   for p in addon.get_previews())
    return {'overall': icons and previews,
            'icons': icons,
            'previews': previews}
开发者ID:mrheides,项目名称:zamboni,代码行数:13,代码来源:views.py


示例4: test_delete_with_file

 def test_delete_with_file(self):
     """Test that when a LangPack instance is deleted, the corresponding
     file on the filesystem is also deleted."""
     langpack = LangPack.objects.create(version='0.1')
     file_path = langpack.file_path
     with public_storage.open(file_path, 'w') as f:
         f.write('sample data\n')
     assert public_storage.exists(file_path)
     try:
         langpack.delete()
         assert not public_storage.exists(file_path)
     finally:
         if public_storage.exists(file_path):
             public_storage.delete(file_path)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:14,代码来源:test_models.py


示例5: test_upload_sign_error_existing

    def test_upload_sign_error_existing(self, sign_app_mock):
        sign_app_mock.side_effect = SigningError
        langpack = self.create_langpack()
        eq_(LangPack.objects.count(), 1)
        original_uuid = langpack.uuid
        original_file_path = langpack.file_path
        original_file_version = langpack.file_version
        original_version = langpack.version
        # create_langpack() doesn't create a fake file, let's add one.
        with public_storage.open(langpack.file_path, 'w') as f:
            f.write('.')
        upload = self.upload('langpack')
        with self.assertRaises(SigningError):
            LangPack.from_upload(upload, instance=langpack)
        # Test that we didn't delete the upload file
        ok_(private_storage.exists(upload.path))
        # Test that we didn't delete the existing filename or alter the
        # existing langpack in the database.
        eq_(LangPack.objects.count(), 1)
        langpack.reload()
        eq_(original_uuid, langpack.uuid)
        eq_(langpack.file_path, original_file_path)
        eq_(original_file_version, langpack.file_version)
        eq_(original_version, langpack.version)
        ok_(public_storage.exists(langpack.file_path))

        # Cleanup
        public_storage.delete(langpack.file_path)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:28,代码来源:test_models.py


示例6: test_upload_existing

 def test_upload_existing(self):
     langpack = self.create_langpack()
     original_uuid = langpack.uuid
     original_file_path = langpack.file_path
     original_file_version = langpack.file_version
     original_manifest = langpack.manifest
     with patch('mkt.webapps.utils.public_storage') as storage_mock:
         # mock storage size before building minifest since we haven't
         # created a real file for this langpack yet.
         storage_mock.size.return_value = 666
         original_minifest = langpack.get_minifest_contents()
     upload = self.upload('langpack')
     langpack = LangPack.from_upload(upload, instance=langpack)
     eq_(langpack.uuid, original_uuid)
     eq_(langpack.version, '1.0.3')
     eq_(langpack.language, 'de')
     eq_(langpack.fxos_version, '2.2')
     eq_(langpack.filename, '%s-%s.zip' % (langpack.uuid, langpack.version))
     eq_(langpack.get_manifest_json(), self.expected_manifest)
     ok_(langpack.file_path.startswith(langpack.path_prefix))
     ok_(langpack.filename in langpack.file_path)
     ok_(langpack.file_path != original_file_path)
     ok_(langpack.file_version > original_file_version)
     ok_(public_storage.exists(langpack.file_path))
     ok_(LangPack.objects.get(pk=langpack.uuid))
     eq_(LangPack.objects.count(), 1)
     ok_(langpack.manifest != original_manifest)
     # We're supposed to have busted the old minifest cache.
     ok_(langpack.get_minifest_contents() != original_minifest)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:29,代码来源:test_models.py


示例7: test_unhide_disabled_files

 def test_unhide_disabled_files(self):
     f = File.objects.get()
     f.status = mkt.STATUS_PUBLIC
     with private_storage.open(f.guarded_file_path, 'wb') as fp:
         fp.write('some data\n')
     f.unhide_disabled_file()
     assert public_storage.exists(f.file_path)
     assert public_storage.open(f.file_path).size
开发者ID:Witia1,项目名称:zamboni,代码行数:8,代码来源:test_models.py


示例8: test_delete_no_file

 def test_delete_no_file(self):
     """Test that the file object can be deleted without the file being
     present."""
     f = File.objects.get()
     filename = f.file_path
     assert not public_storage.exists(filename), ('File exists at: %s' %
                                                  filename)
     f.delete()
开发者ID:Witia1,项目名称:zamboni,代码行数:8,代码来源:test_models.py


示例9: test_delete_no_file

 def test_delete_no_file(self):
     """Test that the LangPack instance can be deleted without the file
     being present."""
     langpack = LangPack.objects.create(version='0.1')
     filename = langpack.file_path
     x = public_storage.exists(filename)
     assert not x, 'File exists at: %s' % filename
     langpack.delete()
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:8,代码来源:test_models.py


示例10: remove_public_signed_file

    def remove_public_signed_file(self):
        """Remove the public signed file if it exists.

        Return the size of the unsigned file, to be used by the caller to
        update the size property on the current instance."""
        if public_storage.exists(self.signed_file_path):
            public_storage.delete(self.signed_file_path)
        return private_storage.size(self.file_path)
开发者ID:1Smert1,项目名称:zamboni,代码行数:8,代码来源:models.py


示例11: test_export_is_created

    def test_export_is_created(self):
        expected_files = [self.app_path, "license.txt", "readme.txt"]
        tarball = self.create_export("tarball-name")
        actual_files = tarball.getnames()
        for expected_file in expected_files:
            assert expected_file in actual_files, expected_file

        # Make sure we didn't touch old tarballs by accident.
        assert public_storage.exists(self.existing_tarball)
开发者ID:jostw,项目名称:zamboni,代码行数:9,代码来源:test_tasks.py


示例12: test_no_resize_when_exact

 def test_no_resize_when_exact(self, fake_req, resize):
     url = 'http://site/media/my.jpg'
     (fake_req.expects('get')
              .returns_fake()
              .expects('iter_content')
              .returns(self.open_img())
              .expects('raise_for_status'))
     size = 64
     self.fetch(url=url, ext_size=size, size=size)
     prod = ProductIcon.objects.get()
     eq_(prod.size, size)
     assert public_storage.exists(prod.storage_path()), 'Image not created'
开发者ID:shahbaz17,项目名称:zamboni,代码行数:12,代码来源:test_tasks.py


示例13: test_resize_transparency

def test_resize_transparency():
    src = get_image_path('transparent.png')
    dest = tempfile.mkstemp(dir=settings.TMP_PATH)[1]
    expected = src.replace('.png', '-expected.png')
    if storage_is_remote():
        copy_to_storage(src, src, src_storage=local_storage)
    try:
        resize_image(src, dest, (32, 32), remove_src=False)
        with public_storage.open(dest) as dfh:
            with open(expected) as efh:
                assert dfh.read() == efh.read()
    finally:
        if public_storage.exists(dest):
            public_storage.delete(dest)
开发者ID:ayushagrawal288,项目名称:zamboni,代码行数:14,代码来源:test_utils_.py


示例14: _uploader

def _uploader(resize_size, final_size):
    img = get_image_path('mozilla.png')
    original_size = (339, 128)

    for rsize, fsize in zip(resize_size, final_size):
        dest_name = os.path.join(settings.ADDON_ICONS_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.png',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        copy_stored_file(img, src.name, src_storage=local_storage,
                         dest_storage=private_storage)

        # Sanity check.
        with private_storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_icon(src.name, dest_name, resize_size)
        eq_(val, {'icon_hash': 'bb362450'})
        dest_image_filename = '%s-%s.png' % (dest_name, rsize)
        with public_storage.open(dest_image_filename) as fp:
            dest_image = Image.open(fp)
            dest_image.load()

        # Assert that the width is always identical.
        eq_(dest_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dest_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (
                fsize[1], dest_image.size[1]))

        if public_storage.exists(dest_image_filename):
            public_storage.delete(dest_image_filename)
        assert not public_storage.exists(dest_image_filename)

    assert not private_storage.exists(src.name)
开发者ID:ayushagrawal288,项目名称:zamboni,代码行数:37,代码来源:test_tasks.py


示例15: test_fetch_ok

 def test_fetch_ok(self, fake_req):
     url = 'http://site/media/my.jpg'
     ext_size = 512
     size = 64
     (fake_req.expects('get')
              .with_args(url, timeout=arg.any())
              .returns_fake()
              .expects('iter_content')
              .returns(self.open_img())
              .expects('raise_for_status'))
     self.fetch(url, ext_size, size)
     prod = ProductIcon.objects.get()
     eq_(prod.ext_size, ext_size)
     eq_(prod.size, size)
     assert public_storage.exists(prod.storage_path()), 'Image not created'
开发者ID:shahbaz17,项目名称:zamboni,代码行数:15,代码来源:test_tasks.py


示例16: _promo_img_uploader

def _promo_img_uploader(resize_size, final_size):
    img = get_image_path('game_1050.jpg')
    original_size = (1050, 591)

    for rsize, fsize in zip(resize_size, final_size):
        dst_name = os.path.join(settings.WEBAPP_PROMO_IMG_PATH, '1234')
        src = tempfile.NamedTemporaryFile(mode='r+w+b', suffix='.jpg',
                                          delete=False)
        # resize_icon removes the original, copy it to a tempfile and use that.
        copy_stored_file(img, src.name, src_storage=local_storage,
                         dst_storage=private_storage)
        # Sanity check.
        with private_storage.open(src.name) as fp:
            src_image = Image.open(fp)
            src_image.load()
        eq_(src_image.size, original_size)

        val = tasks.resize_promo_imgs(src.name, dst_name, resize_size)
        eq_(val, {'promo_img_hash': '215dd2a2'})
        dst_img_name = '%s-%s.png' % (dst_name, rsize)
        with public_storage.open(dst_img_name) as fp:
            dst_image = Image.open(fp)
            dst_image.load()

        # Assert that the width is always identical.
        eq_(dst_image.size[0], fsize[0])
        # Assert that the height can be a wee bit fuzzy.
        assert -1 <= dst_image.size[1] - fsize[1] <= 1, (
            'Got width %d, expected %d' % (
                fsize[1], dst_image.size[1]))

        if public_storage.exists(dst_img_name):
            public_storage.delete(dst_img_name)
        assert not public_storage.exists(dst_img_name)

    assert not private_storage.exists(src.name)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:36,代码来源:test_tasks.py


示例17: test_icon

 def test_icon(self):
     self._step()
     im_hash = self.upload_icon()
     data = self.get_dict()
     data['icon_upload_hash'] = im_hash
     data['icon_type'] = 'image/png'
     rp = self.client.post(self.url, data)
     eq_(rp.status_code, 302)
     ad = self.get_webapp()
     eq_(ad.icon_type, 'image/png')
     for size in mkt.CONTENT_ICON_SIZES:
         fn = '%s-%s.png' % (ad.id, size)
         assert public_storage.exists(
             os.path.join(ad.get_icon_dir(), fn)), ('Expected %s in %s' % (
                 fn, public_storage.listdir(ad.get_icon_dir())[1]))
开发者ID:digideskio,项目名称:zamboni,代码行数:15,代码来源:test_views.py


示例18: _fix_missing_icons

def _fix_missing_icons(id):
    try:
        webapp = Webapp.objects.get(pk=id)
    except Webapp.DoesNotExist:
        _log(id, u'Webapp does not exist')
        return

    # Check for missing icons. If we find one important size missing, call
    # fetch_icon for this app.
    dirname = webapp.get_icon_dir()
    destination = os.path.join(dirname, '%s' % webapp.id)
    for size in (64, 128):
        filename = '%s-%s.png' % (destination, size)
        if not public_storage.exists(filename):
            _log(id, u'Webapp is missing icon size %d' % (size, ))
            return fetch_icon(webapp.pk)
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:16,代码来源:tasks.py


示例19: test_upload_new

 def test_upload_new(self):
     eq_(LangPack.objects.count(), 0)
     upload = self.upload('langpack')
     langpack = LangPack.from_upload(upload)
     ok_(langpack.uuid)
     eq_(langpack.file_version, 1)
     eq_(langpack.version, '1.0.3')
     eq_(langpack.language, 'de')
     eq_(langpack.fxos_version, '2.2')
     eq_(langpack.filename, '%s-%s.zip' % (langpack.uuid, langpack.version))
     ok_(langpack.filename in langpack.file_path)
     ok_(langpack.file_path.startswith(langpack.path_prefix))
     ok_(public_storage.exists(langpack.file_path))
     eq_(langpack.get_manifest_json(), self.expected_manifest)
     ok_(LangPack.objects.get(pk=langpack.uuid))
     eq_(LangPack.objects.count(), 1)
     return langpack
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:17,代码来源:test_models.py


示例20: move_files_to_their_new_locations

def move_files_to_their_new_locations(apps, schema_editor):
    ExtensionVersion = apps.get_model('extensions', 'ExtensionVersion')
    versions = ExtensionVersion.objects.all()
    for version in versions:
        # We lost the version number on old deleted versions, nothing we
        # can do about those. It's fine.
        if version.deleted:
            continue

        # Migrations have no access to custom properties and methods, so we
        # have to re-generate file paths.
        unsigned_prefix = os.path.join(
            settings.EXTENSIONS_PATH, str(version.extension.pk))
        signed_prefix = os.path.join(
            settings.SIGNED_EXTENSIONS_PATH, str(version.extension.pk))
        signed_reviewer_prefix = os.path.join(
            settings.EXTENSIONS_PATH, str(version.extension.pk), 'reviewers')
        filename = 'extension-%s.zip' % version.version

        # Original paths have the version number in them.
        original_unsigned_file_path = os.path.join(unsigned_prefix, filename)
        original_signed_file_path = os.path.join(signed_prefix, filename)
        original_reviewer_signed_file_path = os.path.join(
            signed_reviewer_prefix, filename)

        # New paths use the version pk instead, which will always be available.
        new_filename = 'extension-%s.zip' % version.pk
        new_unsigned_file_path = os.path.join(unsigned_prefix, new_filename)
        new_signed_file_path = os.path.join(signed_prefix, new_filename)
        new_reviewer_signed_file_path = os.path.join(
            signed_reviewer_prefix, new_filename)

        # Do the actual moving.
        if private_storage.exists(original_unsigned_file_path):
            move_stored_file(
                original_unsigned_file_path, new_unsigned_file_path)
        if private_storage.exists(original_reviewer_signed_file_path):
            move_stored_file(
                original_reviewer_signed_file_path,
                new_reviewer_signed_file_path)
        if public_storage.exists(original_signed_file_path):
            move_stored_file(
                original_signed_file_path, new_signed_file_path,
                src_storage=public_storage, dst_storage=public_storage)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:44,代码来源:0020_change_filename_scheme.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python public_storage.open函数代码示例发布时间:2022-05-27
下一篇:
Python public_storage.delete函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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