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

Python storage_utils.copy_stored_file函数代码示例

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

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



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

示例1: from_upload

    def from_upload(cls, upload, version, parse_data={}):
        upload.path = smart_path(nfd_str(upload.path))
        ext = os.path.splitext(upload.path)[1]

        f = cls(version=version)
        f.filename = f.generate_filename(extension=ext or '.zip')
        f.size = private_storage.size(upload.path)  # Size in bytes.
        f.status = mkt.STATUS_PENDING
        # Re-use the file-upload hash if we can, no need to regenerate a new
        # one if we can avoid that.
        f.hash = upload.hash or f.generate_hash(upload.path)
        f.save()

        log.debug('New file: %r from %r' % (f, upload))

        # Move the uploaded file from the temp location.
        copy_stored_file(
            upload.path,
            os.path.join(version.path_prefix, nfd_str(f.filename)),
            src_storage=private_storage,
            dst_storage=private_storage)

        if upload.validation:
            FileValidation.from_json(f, upload.validation)

        return f
开发者ID:mathjazz,项目名称:zamboni,代码行数:26,代码来源:models.py


示例2: test_pngcrush_image_is_called

    def test_pngcrush_image_is_called(self, mock_move):
        expected_suffix = '.opti.png'
        tmp_src = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
        tmp_dest = os.path.splitext(tmp_src.name)[0] + expected_suffix
        copy_stored_file(self.img_path, tmp_dest, src_storage=public_storage,
                         dst_storage=local_storage)
        with mock.patch('tempfile.NamedTemporaryFile',
                        lambda *a, **k: tmp_src):
            rval = tasks.pngcrush_image(self.img_path)
            # pngcrush_image copies the stored file to a local tempfile.
            eq_(open(tmp_src.name).read(),
                public_storage.open(self.img_path).read())

        expected_cmd = ['pngcrush', '-q', '-rem', 'alla', '-brute', '-reduce',
                        '-e', expected_suffix, tmp_src.name]
        # pngcrush_image incokes pngcrush with the tempfile name and writes to
        # another tempfile.
        self.mock_popen.assert_called_once_with(
            expected_cmd, stdin=subprocess.PIPE, stderr=subprocess.PIPE,
            stdout=subprocess.PIPE)
        # The output file is then copied back to storage.
        mock_move.assert_called_once_with(tmp_dest, self.img_path,
                                          dst_storage=public_storage,
                                          src_storage=local_storage)
        eq_(rval, {'image_hash': 'bb362450'})
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:25,代码来源:test_tasks.py


示例3: test_self_copy

 def test_self_copy(self):
     src = self.newfile('src.txt', '<contents>')
     dst = self.path('src.txt')
     copy_stored_file(
         src, dst,
         src_storage=private_storage, dst_storage=private_storage)
     eq_(self.contents(dst), '<contents>')
开发者ID:shahbaz17,项目名称:zamboni,代码行数:7,代码来源:test_storage_utils.py


示例4: setUp

    def setUp(self):
        self.app = Webapp.objects.get(pk=337141)
        self.app.update(is_packaged=True, status=mkt.WEBAPPS_UNREVIEWED_STATUS)
        self.dev = self.app.authors.all()[0]
        self.regular = UserProfile.objects.get(pk=999)
        self.version = self.app.versions.latest()
        self.file = self.version.all_files[0]

        self.versions = [self.version,
                         self.app.versions.create(
                             version='%s.1' % self.version.version)]

        self.files = [self.file,
                      File.objects.create(version=self.versions[1],
                                          filename='webapp.zip')]

        self.login_as_editor()

        for file_obj in self.files:
            src = os.path.join(settings.ROOT, packaged_app)
            if file_obj.status in mkt.LISTED_STATUSES:
                target = public_storage
            else:
                target = private_storage
            copy_stored_file(src, file_obj.file_path,
                             src_storage=local_storage,
                             dst_storage=target)

        self.file_viewer = FileViewer(self.file)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:29,代码来源:test_views.py


示例5: setUp

 def setUp(self):
     fn = get_file('dictionary-test.xpi')
     if storage_is_remote():
         copy_stored_file(
             fn, fn,
             src_storage=local_storage, dst_storage=private_storage)
     self.viewer = FileViewer(make_file(1, fn))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:7,代码来源:test_helpers.py


示例6: run_validator

def run_validator(file_path, url=None):
    """A pre-configured wrapper around the app validator."""

    temp_path = None
    # Make a copy of the file since we can't assume the
    # uploaded file is on the local filesystem.
    temp_path = tempfile.mktemp()
    copy_stored_file(
        file_path, temp_path,
        src_storage=private_storage, dst_storage=local_storage)

    with statsd.timer('mkt.developers.validator'):
        is_packaged = zipfile.is_zipfile(temp_path)
        if is_packaged:
            log.info(u'Running `validate_packaged_app` for path: %s'
                     % (file_path))
            with statsd.timer('mkt.developers.validate_packaged_app'):
                return validate_packaged_app(
                    temp_path,
                    market_urls=settings.VALIDATOR_IAF_URLS,
                    timeout=settings.VALIDATOR_TIMEOUT,
                    spidermonkey=settings.SPIDERMONKEY)
        else:
            log.info(u'Running `validate_app` for path: %s' % (file_path))
            with statsd.timer('mkt.developers.validate_app'):
                return validate_app(open(temp_path).read(),
                                    market_urls=settings.VALIDATOR_IAF_URLS,
                                    url=url)

    # Clean up copied files.
    os.unlink(temp_path)
开发者ID:kolyaflash,项目名称:zamboni,代码行数:31,代码来源:tasks.py


示例7: test_non_ascii

 def test_non_ascii(self):
     src = self.newfile(u'kristi\u0107.txt',
                        u'ivan kristi\u0107'.encode('utf8'))
     dst = self.path(u'somedir/kristi\u0107.txt')
     copy_stored_file(
         src, dst,
         src_storage=private_storage, dst_storage=private_storage)
     eq_(self.contents(dst), 'ivan kristi\xc4\x87')
开发者ID:shahbaz17,项目名称:zamboni,代码行数:8,代码来源:test_storage_utils.py


示例8: setUp

 def setUp(self):
     self.webapp_path = tempfile.mktemp(suffix='.webapp')
     copy_stored_file(
         self.manifest_path('mozball.webapp'), self.webapp_path,
         src_storage=local_storage, dst_storage=private_storage)
     self.tmp_files = []
     self.manifest = dict(name=u'Ivan Krsti\u0107', version=u'1.0',
                          description=u'summary',
                          developer=dict(name=u'Dev Namé'))
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:9,代码来源:test_views_validation.py


示例9: test_preview_size

 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     copy_stored_file(
         get_image_path(name), os.path.join(self.dest, name),
         src_storage=local_storage, dst_storage=private_storage)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:test_forms.py


示例10: setup_files

    def setup_files(self):
        # Clean out any left over stuff.
        public_storage.delete(self.file.signed_file_path)
        private_storage.delete(self.file.signed_reviewer_file_path)

        # Make sure the source file is there.
        if not private_storage.exists(self.file.file_path):
            copy_stored_file(self.packaged_app_path('mozball.zip'),
                             self.file.file_path, src_storage=local_storage,
                             dst_storage=private_storage)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:tests.py


示例11: test_disabled_but_owner

 def test_disabled_but_owner(self):
     self.login('[email protected]')
     self.file.update(status=mkt.STATUS_DISABLED)
     copy_stored_file(self.packaged_app_path('mozball.zip'),
                      self.file.file_path,
                      src_storage=local_storage,
                      dst_storage=private_storage)
     path = private_storage.url(self.file.file_path)
     res = self.client.get(self.url)
     self.assert3xx(res, path)
开发者ID:Witia1,项目名称:zamboni,代码行数:10,代码来源:test_views.py


示例12: test_no_manifest_at_root

 def test_no_manifest_at_root(self):
     path = self.packaged_app_path('no-manifest-at-root.zip')
     if storage_is_remote():
         copy_stored_file(path, path, src_storage=local_storage,
                          dst_storage=private_storage)
     with self.assertRaises(forms.ValidationError) as exc:
         WebAppParser().parse(private_storage.open(path))
     m = exc.exception.messages[0]
     assert m.startswith('The file "manifest.webapp" was not found'), (
         'Unexpected: %s' % m)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:10,代码来源:test_views_validation.py


示例13: get_image

    def get_image(self, filename):
        """Copy image to tmp and return tmp path.

        We do this because the task `resize_preview` removes the src file when
        finished.

        """
        src = get_image_path(filename)
        dst = os.path.join(settings.TMP_PATH, 'preview', filename)
        copy_stored_file(
            src, dst, src_storage=local_storage, dst_storage=private_storage)
        return dst
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:12,代码来源:test_tasks.py


示例14: resize_video

def resize_video(src, pk, user_pk=None, **kw):
    """Try and resize a video and cope if it fails."""
    instance = Preview.objects.get(pk=pk)
    user = UserProfile.objects.get(pk=user_pk) if user_pk else None
    try:
        copy_stored_file(src, src, src_storage=private_storage,
                         dst_storage=local_storage)
        result = _resize_video(src, instance, **kw)
    except Exception, err:
        log.error('Error on processing video: %s' % err)
        _resize_error(src, instance, user)
        raise
开发者ID:tsl143,项目名称:zamboni,代码行数:12,代码来源:tasks.py


示例15: test_disabled_but_admin

 def test_disabled_but_admin(self):
     self.login("[email protected]")
     self.file.update(status=mkt.STATUS_DISABLED)
     copy_stored_file(
         self.packaged_app_path("mozball.zip"),
         self.file.file_path,
         src_storage=local_storage,
         dst_storage=private_storage,
     )
     path = private_storage.url(self.file.file_path)
     res = self.client.get(self.url)
     self.assert3xx(res, path)
开发者ID:ujdhesa,项目名称:zamboni,代码行数:12,代码来源:test_views.py


示例16: compress_export

def compress_export(tarball_name, date):
    # We need a temporary directory on the local filesystem that will contain
    # all files in order to call `tar`.
    local_source_dir = tempfile.mkdtemp()

    apps_dirpath = os.path.join(settings.DUMPED_APPS_PATH, 'apps')

    # In case apps_dirpath is empty, add a dummy file to make the apps
    # directory in the tar archive non-empty. It should not happen in prod, but
    # it's nice to have it to prevent the task from failing entirely.
    with private_storage.open(
            os.path.join(apps_dirpath, '0', '.keep'), 'w') as fd:
        fd.write('.')

    # Now, copy content from private_storage to that temp directory. We don't
    # need to worry about creating the directories locally, the storage class
    # does that for us.
    for dirpath, dirnames, filenames in walk_storage(
            apps_dirpath, storage=private_storage):
        for filename in filenames:
            src_path = os.path.join(dirpath, filename)
            dst_path = os.path.join(
                local_source_dir, 'apps', os.path.basename(dirpath), filename)
            copy_stored_file(
                src_path, dst_path, src_storage=private_storage,
                dst_storage=local_storage)

    # Also add extra files to the temp directory.
    extra_filenames = compile_extra_files(local_source_dir, date)

    # All our files are now present locally, let's generate a local filename
    # that will contain the final '.tar.gz' before it's copied over to
    # public storage.
    local_target_file = tempfile.NamedTemporaryFile(
        suffix='.tgz', prefix='dumped-apps-')

    # tar ALL the things!
    cmd = ['tar', 'czf', local_target_file.name, '-C',
           local_source_dir] + ['apps'] + extra_filenames
    task_log.info(u'Creating dump {0}'.format(local_target_file.name))
    subprocess.call(cmd)

    # Now copy the local tgz to the public storage.
    remote_target_filename = os.path.join(
        settings.DUMPED_APPS_PATH, 'tarballs', '%s.tgz' % tarball_name)
    copy_stored_file(local_target_file.name, remote_target_filename,
                     src_storage=local_storage,
                     dst_storage=public_storage)

    # Clean-up.
    local_target_file.close()
    rm_directory(local_source_dir)
    return remote_target_filename
开发者ID:mrheides,项目名称:zamboni,代码行数:53,代码来源:tasks.py


示例17: test_parse_packaged_BOM

 def test_parse_packaged_BOM(self):
     path = self.packaged_app_path('mozBOM.zip')
     if storage_is_remote():
         copy_stored_file(path, path, src_storage=local_storage,
                          dst_storage=private_storage)
     wp = WebAppParser().parse(private_storage.open(path))
     eq_(wp['guid'], None)
     eq_(wp['name']['en-US'], u'Packaged MozBOM ょ')
     eq_(wp['description']['en-US'], u'Exciting BOM action!')
     eq_(wp['description']['es'], u'¡Acción BOM!')
     eq_(wp['description']['it'], u'Azione BOM!')
     eq_(wp['version'], '1.0')
     eq_(wp['default_locale'], 'en-US')
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:13,代码来源:test_views_validation.py


示例18: test_preview_size

 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     copy_stored_file(
         get_image_path(name), os.path.join(self.dest, name),
         src_storage=local_storage, dst_storage=private_storage)
     assert form.is_valid(), form.errors
     form.save(self.addon)
     # Since the task is a post-request-task and we are outside the normal
     # request-response cycle, manually send the tasks.
     post_request_task._send_tasks()
     eq_(self.addon.previews.all()[0].sizes,
         {u'image': [250, 297], u'thumbnail': [100, 119]})
开发者ID:ujdhesa,项目名称:zamboni,代码行数:13,代码来源:test_forms.py


示例19: setUp

 def setUp(self):
     self.img_path = tempfile.mktemp()
     copy_stored_file(get_image_path('mozilla.png'),
                      self.img_path,
                      src_storage=local_storage,
                      dest_storage=public_storage)
     patcher = mock.patch('subprocess.Popen')
     self.mock_popen = patcher.start()
     attrs = {
         'returncode': 0,
         'communicate.return_value': ('ouput', 'error')
     }
     self.mock_popen.return_value.configure_mock(**attrs)
     self.addCleanup(patcher.stop)
开发者ID:ayushagrawal288,项目名称:zamboni,代码行数:14,代码来源:test_tasks.py


示例20: setUp

 def setUp(self):
     super(TestTask, self).setUp()
     self.app = Webapp.objects.get(pk=337141)
     self.preview = Preview.objects.create(
         addon=self.app, thumbnail_path=tempfile.mkstemp()[1],
         image_path=tempfile.mkstemp()[1])
     # Copy files to private storage where `resize_video` expects it.
     self.tmp_good = tempfile.NamedTemporaryFile(suffix='.webm').name
     self.tmp_bad = tempfile.NamedTemporaryFile(suffix='.png').name
     copy_stored_file(files['good'], self.tmp_good,
                      src_storage=local_storage,
                      dst_storage=private_storage)
     copy_stored_file(files['bad'], self.tmp_bad,
                      src_storage=local_storage,
                      dst_storage=private_storage)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:15,代码来源:tests.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python storage_utils.storage_is_remote函数代码示例发布时间:2022-05-27
下一篇:
Python messages.success函数代码示例发布时间: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