当前位置: 首页>>代码示例>>Python>>正文


Python helpers.copyfileobj函数代码示例

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


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

示例1: 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()
    with open(temp_path, "wb") as local_f:
        with private_storage.open(file_path) as remote_f:
            copyfileobj(remote_f, local_f)

    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:jamesthechamp,项目名称:zamboni,代码行数:29,代码来源:tasks.py

示例2: test_preview_size

 def test_preview_size(self):
     name = "non-animated.gif"
     form = forms.PreviewForm({"upload_hash": name, "position": 1})
     with storage.open(os.path.join(self.dest, name), "wb") as f:
         copyfileobj(open(get_image_path(name)), f)
     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:petercpg,项目名称:zamboni,代码行数:8,代码来源:test_forms.py

示例3: setUp

 def setUp(self):
     self.webapp_path = tempfile.mktemp(suffix='.webapp')
     with storage.open(self.webapp_path, 'wb') as f:
         copyfileobj(open(os.path.join(os.path.dirname(__file__),
                                       'addons', 'mozball.webapp')),
                     f)
     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:Dreadchild,项目名称:zamboni,代码行数:10,代码来源:test_views_validation.py

示例4: test_preview_size

 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name,
                               'position': 1})
     with storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     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:Dreadchild,项目名称:zamboni,代码行数:10,代码来源:test_forms.py

示例5: 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():
         with open(path) as local_f:
             with storage.open(path, 'w') as remote_f:
                 copyfileobj(local_f, remote_f)
     with self.assertRaises(forms.ValidationError) as exc:
         WebAppParser().parse(path)
     m = exc.exception.messages[0]
     assert m.startswith('The file "manifest.webapp" was not found'), (
         'Unexpected: %s' % m)
开发者ID:Jobava,项目名称:zamboni,代码行数:11,代码来源:test_views_validation.py

示例6: upload

    def upload(self, name):
        if os.path.splitext(name)[-1] not in ['.webapp', '.zip']:
            name = name + '.zip'

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={}))
        fname = nfd_str(self.packaged_app_path(name))
        if not storage.exists(fname):
            with storage.open(fname, 'w') as fs:
                copyfileobj(open(fname), fs)
        d = dict(path=fname, name=name,
                 hash='sha256:%s' % name, validation=v)
        return FileUpload.objects.create(**d)
开发者ID:clouserw,项目名称:zamboni,代码行数:12,代码来源:test_models.py

示例7: test_icon_modified

    def test_icon_modified(self, update_mock):
        name = 'transparent.png'
        form = forms.AddonFormMedia({'icon_upload_hash': name},
                                    request=self.request,
                                    instance=self.addon)

        dest = os.path.join(self.icon_path, name)
        with storage.open(dest, 'w') as f:
            copyfileobj(open(get_image_path(name)), f)
        assert form.is_valid()
        form.save(addon=self.addon)
        assert update_mock.called
开发者ID:jinankjain,项目名称:zamboni,代码行数:12,代码来源:test_forms.py

示例8: upload

    def upload(self, name, **kwargs):
        if os.path.splitext(name)[-1] not in [".webapp", ".zip"]:
            name = name + ".zip"

        v = json.dumps(dict(errors=0, warnings=1, notices=2, metadata={}))
        fname = nfd_str(self.packaged_app_path(name))
        if not storage.exists(fname):
            with storage.open(fname, "w") as fs:
                copyfileobj(open(fname), fs)
        data = {"path": fname, "name": name, "hash": "sha256:%s" % name, "validation": v}
        data.update(**kwargs)
        return FileUpload.objects.create(**data)
开发者ID:jobava-mozilla,项目名称:zamboni,代码行数:12,代码来源:test_models.py

示例9: test_preview_size

 def test_preview_size(self):
     name = 'non-animated.gif'
     form = forms.PreviewForm({'upload_hash': name, 'position': 1})
     with private_storage.open(os.path.join(self.dest, name), 'wb') as f:
         copyfileobj(open(get_image_path(name)), f)
     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:ayushagrawal288,项目名称:zamboni,代码行数:12,代码来源:test_forms.py

示例10: validator

def validator(upload_id, **kw):
    if not settings.VALIDATE_ADDONS:
        return None
    log.info(u'[FileUpload:%s] Validating app.' % upload_id)
    try:
        upload = FileUpload.objects.get(pk=upload_id)
    except FileUpload.DoesNotExist:
        log.info(u'[FileUpload:%s] Does not exist.' % upload_id)
        return

    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()
    with open(temp_path, 'wb') as local_f:
        with storage.open(upload.path) as remote_f:
            copyfileobj(remote_f, local_f)

    try:
        validation_result = run_validator(temp_path, url=kw.get('url'))
        if upload.validation:
            # If there's any preliminary validation result, merge it with the
            # actual validation result.
            dec_prelim_result = json.loads(upload.validation)
            if 'prelim' in dec_prelim_result:
                dec_validation_result = json.loads(validation_result)
                # Merge the messages.
                dec_validation_result['messages'] += (
                    dec_prelim_result['messages'])
                # Merge the success value.
                if dec_validation_result['success']:
                    dec_validation_result['success'] = (
                        dec_prelim_result['success'])
                # Merge the error count (we only raise errors, not warnings).
                dec_validation_result['errors'] += dec_prelim_result['errors']

                # Put the validation result back into JSON.
                validation_result = json.dumps(dec_validation_result)

        upload.validation = validation_result
        upload.save()  # We want to hit the custom save().
    except Exception:
        # Store the error with the FileUpload job, then raise
        # it for normal logging.
        tb = traceback.format_exception(*sys.exc_info())
        upload.update(task_error=''.join(tb))
        # Don't raise if we're being eager, setting the error is enough.
        if not settings.CELERY_ALWAYS_EAGER:
            raise

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

示例11: test_parse_packaged_BOM

 def test_parse_packaged_BOM(self):
     path = self.packaged_app_path('mozBOM.zip')
     if storage_is_remote():
         with open(path) as local_f:
             with storage.open(path, 'w') as remote_f:
                 copyfileobj(local_f, remote_f)
     wp = WebAppParser().parse(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:Jobava,项目名称:zamboni,代码行数:14,代码来源:test_views_validation.py

示例12: 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:
        if not os.path.exists(src):
            # We're probably using S3 in this case.
            try:
                os.makedirs(os.path.dirname(src))
            except OSError:  # already exists
                pass
            copyfileobj(public_storage.open(src), open(src, 'w'))
        result = _resize_video(src, instance, **kw)
    except Exception, err:
        log.error('Error on processing video: %s' % err)
        _resize_error(src, instance, user)
        raise
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:17,代码来源:tasks.py

示例13: test_parse_packaged

 def test_parse_packaged(self):
     path = self.packaged_app_path('mozball.zip')
     if storage_is_remote():
         with open(path) as local_f:
             with storage.open(path, 'w') as remote_f:
                 copyfileobj(local_f, remote_f)
     wp = WebAppParser().parse(path)
     eq_(wp['guid'], None)
     eq_(wp['name']['en-US'], u'Packaged MozillaBall ょ')
     eq_(wp['description']['en-US'],
         u'Exciting Open Web development action!')
     eq_(wp['description']['es'],
         u'¡Acción abierta emocionante del desarrollo del Web!')
     eq_(wp['description']['it'],
         u'Azione aperta emozionante di sviluppo di fotoricettore!')
     eq_(wp['version'], '1.0')
     eq_(wp['default_locale'], 'en-US')
开发者ID:Jobava,项目名称:zamboni,代码行数:17,代码来源:test_views_validation.py

示例14: packaged_copy_over

 def packaged_copy_over(self, dest, name):
     with storage.open(dest, 'wb') as f:
         copyfileobj(open(self.packaged_app_path(name)), f)
开发者ID:MorrisJobke,项目名称:zamboni,代码行数:3,代码来源:__init__.py

示例15: manifest_copy_over

 def manifest_copy_over(self, dest, name):
     with storage.open(dest, 'wb') as f:
         copyfileobj(open(self.manifest_path(name)), f)
开发者ID:MorrisJobke,项目名称:zamboni,代码行数:3,代码来源:__init__.py


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