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


Python private_storage.open函数代码示例

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


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

示例1: generate_packaged_app

def generate_packaged_app(namedict, apptype, categories, developer_name,
                          privacy_policy=None, device_types=(),
                          permissions=(), versions=(),
                          default_locale='en-US', package_file=None,
                          status=4, **kw):
    now = datetime.datetime.now()
    app = app_factory(categories=categories, name=namedict[default_locale],
                      complete=False, rated=True, is_packaged=True,
                      privacy_policy=privacy_policy,
                      version_kw={
                          'version': '1.0',
                          'reviewed': now if status >= 4 else None,
                          '_developer_name': developer_name},
                      file_kw={'status': status})
    if device_types:
        for dt in device_types:
            app.addondevicetype_set.create(device_type=DEVICE_CHOICES_IDS[dt])
    else:
        app.addondevicetype_set.create(device_type=1)
    f = app.latest_version.all_files[0]
    f.update(filename=f.generate_filename())
    fp = os.path.join(app.latest_version.path_prefix, f.filename)
    if package_file:
        package_file_file = open(package_file)
        manifest = WebAppParser().get_json_data(package_file_file)
        AppManifest.objects.create(
            version=app.latest_version, manifest=json.dumps(manifest))
        # copy package_file to storage like a normal app.
        private_storage.save(fp, package_file_file)
        app.update_version()
        return app
    with private_storage.open(fp, 'w') as out:
        generate_app_package(app, out, apptype,
                             permissions, namedict,
                             version=app.latest_version)
    for i, vspec in enumerate(versions, 1):
        st = STATUS_CHOICES_API_LOOKUP[vspec.get("status", "public")]
        rtime = (now + datetime.timedelta(i))
        v = version_factory(version="1." + str(i), addon=app,
                            reviewed=rtime if st >= 4 else None,
                            nomination=rtime if st > 0 else None,
                            created=rtime,
                            file_kw={'status': st},
                            _developer_name=developer_name)
        f = v.files.all()[0]
        f.update(filename=f.generate_filename())
        fp = os.path.join(app.latest_version.path_prefix, f.filename)
        with private_storage.open(fp, 'w') as out:
            generate_app_package(app, out, vspec.get("type", apptype),
                                 vspec.get("permissions", permissions),
                                 namedict, version=v)
        app.update_version()
    return app
开发者ID:carriercomm,项目名称:zamboni,代码行数:53,代码来源:fakedata.py

示例2: mock_sign

def mock_sign(version_id, reviewer=False):
    """
    This is a mock for using in tests, where we really don't want to be
    actually signing the apps. This just copies the file over and returns
    the path. It doesn't have much error checking.
    """
    version = Version.objects.get(pk=version_id)
    file_obj = version.all_files[0]
    path = (file_obj.signed_reviewer_file_path if reviewer else
            file_obj.signed_file_path)
    with private_storage.open(path, 'w') as dest_f:
        shutil.copyfileobj(private_storage.open(file_obj.file_path), dest_f)
    return path
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:13,代码来源:tests.py

示例3: resize_preview

def resize_preview(src, pk, **kw):
    """Resizes preview images and stores the sizes on the preview."""
    instance = Preview.objects.get(pk=pk)
    thumb_dst, full_dst = instance.thumbnail_path, instance.image_path
    sizes = instance.sizes or {}
    log.info("[[email protected]] Resizing preview and storing size: %s" % thumb_dst)
    try:
        thumbnail_size = APP_PREVIEW_SIZES[0][:2]
        image_size = APP_PREVIEW_SIZES[1][:2]
        with private_storage.open(src, "rb") as fp:
            size = Image.open(fp).size
        if size[0] > size[1]:
            # If the image is wider than tall, then reverse the wanted size
            # to keep the original aspect ratio while still resizing to
            # the correct dimensions.
            thumbnail_size = thumbnail_size[::-1]
            image_size = image_size[::-1]

        if kw.get("generate_thumbnail", True):
            sizes["thumbnail"] = resize_image(src, thumb_dst, thumbnail_size, remove_src=False)
        if kw.get("generate_image", True):
            sizes["image"] = resize_image(src, full_dst, image_size, remove_src=False)
        instance.sizes = sizes
        instance.save()
        log.info("Preview resized to: %s" % thumb_dst)

        # Remove src file now that it has been processed.
        private_storage.delete(src)

        return True

    except Exception, e:
        log.error("Error saving preview: %s; %s" % (e, thumb_dst))
开发者ID:ujdhesa,项目名称:zamboni,代码行数:33,代码来源:tasks.py

示例4: reviewer_sign_file

 def reviewer_sign_file(self):
     """Sign the original file (`file_path`) with reviewer certs, then move
     the signed file to the reviewers-specific signed path
     (`reviewer_signed_file_path`) on private storage."""
     if not self.extension.uuid:
         raise SigningError('Need uuid to be set to sign')
     if not self.pk:
         raise SigningError('Need version pk to be set to sign')
     ids = json.dumps({
         # Reviewers get a unique 'id' so the reviewer installed add-on
         # won't conflict with the public add-on, and also so even multiple
         # versions of the same add-on can be installed side by side with
         # other versions.
         'id': 'reviewer-{guid}-{version_id}'.format(
             guid=self.extension.uuid, version_id=self.pk),
         'version': self.pk
     })
     with statsd.timer('extensions.sign_reviewer'):
         try:
             # This will read the file from self.file_path, generate a
             # reviewer signature and write the signed file to
             # self.reviewer_signed_file_path.
             sign_app(private_storage.open(self.file_path),
                      self.reviewer_signed_file_path, ids, reviewer=True)
         except SigningError:
             log.info(
                 '[ExtensionVersion:%s] Reviewer Signing failed' % self.pk)
             if private_storage.exists(self.reviewer_signed_file_path):
                 private_storage.delete(self.reviewer_signed_file_path)
             raise
开发者ID:1Smert1,项目名称:zamboni,代码行数:30,代码来源:models.py

示例5: generate_hash

 def generate_hash(self, filename=None):
     """Generate a hash for a file."""
     hash = hashlib.sha256()
     with private_storage.open(filename or self.file_path, 'rb') as obj:
         for chunk in iter(lambda: obj.read(1024), ''):
             hash.update(chunk)
     return 'sha256:%s' % hash.hexdigest()
开发者ID:mathjazz,项目名称:zamboni,代码行数:7,代码来源:models.py

示例6: test_view_left_binary

 def test_view_left_binary(self):
     self.file_viewer.extract()
     filename = os.path.join(self.file_viewer.left.dest, 'script.js')
     with private_storage.open(filename, 'w') as f:
         f.write('MZ')
     res = self.client.get(self.file_url(not_binary))
     assert 'This file is not viewable online' in res.content
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:7,代码来源:test_views.py

示例7: sign_file

    def sign_file(self):
        """Sign the original file (`file_path`), then move signed extension
        file to the signed path (`signed_file_path`) on public storage. The
        original file remains on private storage.

        Return the signed file size."""
        if not self.extension.uuid:
            raise SigningError('Need uuid to be set to sign')
        if not self.pk:
            raise SigningError('Need version pk to be set to sign')

        ids = json.dumps({
            # 'id' needs to be an unique identifier not shared with anything
            # else (other extensions, langpacks, webapps...), but should not
            # change when there is an update.
            'id': self.extension.uuid,
            # 'version' should be an integer and should be monotonically
            # increasing.
            'version': self.pk
        })
        with statsd.timer('extensions.sign'):
            try:
                # This will read the file from self.file_path, generate a
                # signature and write the signed file to self.signed_file_path.
                sign_app(private_storage.open(self.file_path),
                         self.signed_file_path, ids)
            except SigningError:
                log.info('[ExtensionVersion:%s] Signing failed' % self.pk)
                self.remove_public_signed_file()  # Clean up.
                raise
        return public_storage.size(self.signed_file_path)
开发者ID:1Smert1,项目名称:zamboni,代码行数:31,代码来源:models.py

示例8: reviewer_sign_file

 def reviewer_sign_file(self):
     """Sign the original file (`file_path`) with reviewer certs, then move
     the signed file to the reviewers-specific signed path
     (`reviewer_signed_file_path`) on private storage."""
     if not self.extension.uuid:
         raise SigningError('Need uuid to be set to sign')
     if not self.pk:
         raise SigningError('Need version pk to be set to sign')
     ids = json.dumps({
         'id': self.review_id,
         'version': self.pk
     })
     with statsd.timer('extensions.sign_reviewer'):
         try:
             # This will read the file from self.file_path, generate a
             # reviewer signature and write the signed file to
             # self.reviewer_signed_file_path.
             sign_app(private_storage.open(self.file_path),
                      self.reviewer_signed_file_path, ids, reviewer=True)
         except SigningError:
             log.info(
                 '[ExtensionVersion:%s] Reviewer Signing failed' % self.pk)
             if private_storage.exists(self.reviewer_signed_file_path):
                 private_storage.delete(self.reviewer_signed_file_path)
             raise
开发者ID:Witia1,项目名称:zamboni,代码行数:25,代码来源:models.py

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

示例10: make_packaged_app

def make_packaged_app():
    ap = app_factory()
    ap.update(is_packaged=True)
    f = ap.latest_version.all_files[0]
    fp = os.path.join(ap.latest_version.path_prefix, f.filename)
    with private_storage.open(fp, 'w') as out:
        out.write('.')
    return ap
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:8,代码来源:test_views.py

示例11: test_success_add_file

    def test_success_add_file(self, validator_mock):
        with self.patch_requests() as ur:
            ur.iter_content.return_value = mock.Mock(next=lambda: 'woo')

        tasks.fetch_manifest('http://xx.com/manifest.json', self.upload.pk)
        upload = FileUpload.objects.get(pk=self.upload.pk)
        eq_(upload.name, 'http://xx.com/manifest.json')
        eq_(private_storage.open(upload.path).read(), 'woo')
开发者ID:ayushagrawal288,项目名称:zamboni,代码行数:8,代码来源:test_tasks.py

示例12: test_file_order

 def test_file_order(self):
     self.viewer.extract()
     dest = self.viewer.dest
     private_storage.open(os.path.join(dest, 'manifest.webapp'),
                          'w').close()
     subdir = os.path.join(dest, 'chrome')
     with private_storage.open(os.path.join(subdir, 'foo'), 'w') as f:
         f.write('.')
     if not private_storage.exists(subdir):
         # Might be on S3, which doesn't have directories (and
         # django-storages doesn't support empty files).
         with private_storage.open(subdir, 'w') as f:
             f.write('.')
     cache.clear()
     files = self.viewer.get_files().keys()
     rt = files.index(u'chrome')
     eq_(files[rt:rt + 3], [u'chrome', u'chrome/foo', u'dictionaries'])
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:17,代码来源:test_helpers.py

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

示例14: test_bom

 def test_bom(self):
     dest = os.path.join(settings.TMP_PATH, 'test_bom')
     with private_storage.open(dest, 'w') as f:
         f.write('foo'.encode('utf-16'))
     self.viewer.select('foo')
     self.viewer.selected = {'full': dest, 'size': 1}
     eq_(self.viewer.read_file(), u'foo')
     private_storage.delete(dest)
开发者ID:Fjoerfoks,项目名称:zamboni,代码行数:8,代码来源:test_helpers.py

示例15: test_inject_ids

 def test_inject_ids(self, post):
     post().status_code = 200
     post().content = '{"zigbert.rsa": ""}'
     packaged.sign(self.version.pk)
     zf = zipfile.ZipFile(private_storage.open(self.file.signed_file_path),
                          mode='r')
     ids_data = zf.read('META-INF/ids.json')
     eq_(sorted(json.loads(ids_data).keys()), ['id', 'version'])
开发者ID:jamesthechamp,项目名称:zamboni,代码行数:8,代码来源:tests.py


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