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


Python storage_utils.copy_stored_file函数代码示例

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


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


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