Exemple #1
0
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}
Exemple #2
0
 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)
Exemple #3
0
 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)
Exemple #4
0
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}
Exemple #5
0
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}
Exemple #6
0
 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)
Exemple #7
0
 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)
Exemple #8
0
 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)
Exemple #9
0
 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)
Exemple #10
0
    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)
Exemple #11
0
    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)
Exemple #12
0
 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()
Exemple #13
0
    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)
Exemple #14
0
    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)
Exemple #15
0
 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()
Exemple #16
0
 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
Exemple #17
0
 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()
Exemple #18
0
 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()
Exemple #19
0
 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
Exemple #20
0
    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)
Exemple #21
0
 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'
Exemple #22
0
 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'
Exemple #23
0
    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)
Exemple #24
0
 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'
Exemple #25
0
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)
Exemple #26
0
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)
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)
Exemple #28
0
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)
Exemple #29
0
 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'
Exemple #30
0
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)
Exemple #31
0
 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]))
Exemple #32
0
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)
Exemple #33
0
 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]))
Exemple #34
0
 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
Exemple #35
0
def cleanup_file(sender, instance, **kw):
    """ On delete of the file object from the database, unlink the file from
    the file system """
    if kw.get('raw') or not instance.filename:
        return
    # Use getattr so the paths are accessed inside the try block.
    for path in ('file_path', 'guarded_file_path', 'signed_file_path'):
        try:
            filename = getattr(instance, path, None)
        except models.ObjectDoesNotExist:
            return
        if filename and (public_storage.exists(filename) or
                         private_storage.exists(filename)):
            log.info('Removing filename: %s for file: %s'
                     % (filename, instance.pk))
            public_storage.delete(filename)
            private_storage.delete(filename)
Exemple #36
0
 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
Exemple #37
0
def cleanup_file(sender, instance, **kw):
    """ On delete of the file object from the database, unlink the file from
    the file system """
    if kw.get('raw') or not instance.filename:
        return
    # Use getattr so the paths are accessed inside the try block.
    for path in ('file_path', 'guarded_file_path', 'reviewer_signed_file_path',
                 'signed_file_path'):
        try:
            filename = getattr(instance, path, None)
        except models.ObjectDoesNotExist:
            return
        if filename and (public_storage.exists(filename) or
                         private_storage.exists(filename)):
            log.info('Removing filename: %s for file: %s'
                     % (filename, instance.pk))
            public_storage.delete(filename)
            private_storage.delete(filename)
Exemple #38
0
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)
Exemple #39
0
    def handle_file_operations(self, upload):
        """Handle file operations on an instance by using the FileUpload object
        passed to set filename, file_version on the LangPack instance, and
        moving the temporary file to its final destination."""
        upload.path = smart_path(nfd_str(upload.path))
        if not self.uuid:
            self.reset_uuid()
        if public_storage.exists(self.file_path):
            # The filename should not exist. If it does, it means we are trying
            # to re-upload the same version. This should have been caught
            # before, so just raise an exception.
            raise RuntimeError(
                'Trying to upload a file to a destination that already exists')

        self.file_version = self.file_version + 1

        # Because we are only dealing with langpacks generated by Mozilla atm,
        # we can directly sign the file before copying it to its final
        # destination. The filename changes with the version, so when a new
        # file is uploaded we should still be able to serve the old one until
        # the new info is stored in the db.
        self.sign_and_move_file(upload)
Exemple #40
0
 def sign_and_move_file(self, upload):
     ids = json.dumps({
         # 'id' needs to be an unique identifier not shared with anything
         # else (other langpacks, webapps, extensions...), but should not
         # change when there is an update. Since our PKs are uuid it's the
         # best choice.
         'id': self.pk,
         # 'version' should be an integer and should be monotonically
         # increasing.
         'version': self.file_version
     })
     with statsd.timer('langpacks.sign'):
         try:
             # This will read the upload.path file, generate a signature
             # and write the signed file to self.file_path.
             sign_app(private_storage.open(upload.path),
                      self.file_path, ids)
         except SigningError:
             log.info('[LangPack:%s] Signing failed' % self.pk)
             if public_storage.exists(self.file_path):
                 public_storage.delete(self.file_path)
             raise
Exemple #41
0
    def handle_file_operations(self, upload):
        """Handle file operations on an instance by using the FileUpload object
        passed to set filename, file_version on the LangPack instance, and
        moving the temporary file to its final destination."""
        upload.path = smart_path(nfd_str(upload.path))
        if not self.uuid:
            self.reset_uuid()
        if public_storage.exists(self.file_path):
            # The filename should not exist. If it does, it means we are trying
            # to re-upload the same version. This should have been caught
            # before, so just raise an exception.
            raise RuntimeError(
                'Trying to upload a file to a destination that already exists')

        self.file_version = self.file_version + 1

        # Because we are only dealing with langpacks generated by Mozilla atm,
        # we can directly sign the file before copying it to its final
        # destination. The filename changes with the version, so when a new
        # file is uploaded we should still be able to serve the old one until
        # the new info is stored in the db.
        self.sign_and_move_file(upload)
Exemple #42
0
 def sign_and_move_file(self, upload):
     ids = json.dumps({
         # 'id' needs to be an unique identifier not shared with anything
         # else (other langpacks, webapps, extensions...), but should not
         # change when there is an update. Since our PKs are uuid it's the
         # best choice.
         'id': self.pk,
         # 'version' should be an integer and should be monotonically
         # increasing.
         'version': self.file_version
     })
     with statsd.timer('langpacks.sign'):
         try:
             # This will read the upload.path file, generate a signature
             # and write the signed file to self.file_path.
             sign_app(private_storage.open(upload.path), self.file_path,
                      ids)
         except SigningError:
             log.info('[LangPack:%s] Signing failed' % self.pk)
             if public_storage.exists(self.file_path):
                 public_storage.delete(self.file_path)
             raise
Exemple #43
0
def remove_icons(destination):
    for size in mkt.CONTENT_ICON_SIZES:
        filename = '%s-%s.png' % (destination, size)
        if public_storage.exists(filename):
            public_storage.delete(filename)
Exemple #44
0
 def clean_files(self, f):
     if not public_storage.exists(f.file_path):
         with public_storage.open(f.file_path, 'w') as fp:
             fp.write('sample data\n')
Exemple #45
0
def remove_promo_imgs(destination):
    for size in mkt.PROMO_IMG_SIZES:
        filename = '%s-%s.png' % (destination, size)
        if public_storage.exists(filename):
            public_storage.delete(filename)
Exemple #46
0
 def clean_files(self, f):
     if not public_storage.exists(f.file_path):
         with public_storage.open(f.file_path, 'w') as fp:
             fp.write('sample data\n')
Exemple #47
0
 def remove_signed_file(self):
     if public_storage.exists(self.signed_file_path):
         public_storage.delete(self.signed_file_path)
Exemple #48
0
def remove_icons(destination):
    for size in mkt.CONTENT_ICON_SIZES:
        filename = '%s-%s.png' % (destination, size)
        if public_storage.exists(filename):
            public_storage.delete(filename)
Exemple #49
0
def remove_promo_imgs(destination):
    for size in mkt.PROMO_IMG_SIZES:
        filename = '%s-%s.png' % (destination, size)
        if public_storage.exists(filename):
            public_storage.delete(filename)