Пример #1
0
    def delete(self):
        log.info(u'Version deleted: %r (%s)' % (self, self.id))
        mkt.log(mkt.LOG.DELETE_VERSION, self.webapp, str(self.version))

        models.signals.pre_delete.send(sender=Version, instance=self)

        was_current = False
        if self == self.webapp.current_version:
            was_current = True

        self.update(deleted=True)

        # Set file status to disabled.
        f = self.all_files[0]
        f.update(status=mkt.STATUS_DISABLED, _signal=False)
        f.hide_disabled_file()

        # If version deleted was the current version and there now exists
        # another current_version, we need to call some extra methods to update
        # various bits for packaged apps.
        if was_current and self.webapp.current_version:
            self.webapp.update_name_from_package_manifest()
            self.webapp.update_supported_locales()

        if self.webapp.is_packaged:
            # Unlink signed packages if packaged app.
            public_storage.delete(f.signed_file_path)
            log.info(u'Unlinked file: %s' % f.signed_file_path)
            private_storage.delete(f.signed_reviewer_file_path)
            log.info(u'Unlinked file: %s' % f.signed_reviewer_file_path)

        models.signals.post_delete.send(sender=Version, instance=self)
Пример #2
0
    def delete(self):
        log.info(u'Version deleted: %r (%s)' % (self, self.id))
        mkt.log(mkt.LOG.DELETE_VERSION, self.addon, str(self.version))

        models.signals.pre_delete.send(sender=Version, instance=self)

        was_current = False
        if self == self.addon.current_version:
            was_current = True

        self.update(deleted=True)

        # Set file status to disabled.
        f = self.all_files[0]
        f.update(status=mkt.STATUS_DISABLED, _signal=False)
        f.hide_disabled_file()

        # If version deleted was the current version and there now exists
        # another current_version, we need to call some extra methods to update
        # various bits for packaged apps.
        if was_current and self.addon.current_version:
            self.addon.update_name_from_package_manifest()
            self.addon.update_supported_locales()

        if self.addon.is_packaged:
            # Unlink signed packages if packaged app.
            public_storage.delete(f.signed_file_path)
            log.info(u'Unlinked file: %s' % f.signed_file_path)
            private_storage.delete(f.signed_reviewer_file_path)
            log.info(u'Unlinked file: %s' % f.signed_reviewer_file_path)

        models.signals.post_delete.send(sender=Version, instance=self)
Пример #3
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)
Пример #4
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)
Пример #5
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)
Пример #6
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)
Пример #7
0
def delete_preview_files(id, **kw):
    task_log.info('[1@None] Removing preview with id of %s.' % id)

    p = Preview(id=id)
    for f in (p.thumbnail_path, p.image_path):
        try:
            public_storage.delete(f)
        except Exception, e:
            task_log.error('Error deleting preview file (%s): %s' % (f, e))
Пример #8
0
def delete_preview_files(id, **kw):
    task_log.info('[1@None] Removing preview with id of %s.' % id)

    p = Preview(id=id)
    for f in (p.thumbnail_path, p.image_path):
        try:
            public_storage.delete(f)
        except Exception, e:
            task_log.error('Error deleting preview file (%s): %s' % (f, e))
Пример #9
0
    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)
Пример #10
0
    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)
Пример #11
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)
Пример #12
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)
Пример #13
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)
Пример #14
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)
Пример #15
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)
Пример #16
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)
Пример #17
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)
Пример #18
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)
Пример #19
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)
Пример #20
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
Пример #21
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
Пример #22
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)
Пример #23
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)
Пример #24
0
 def tearDown(self):
     public_storage.delete(self.img_path)
Пример #25
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)
Пример #26
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)
Пример #27
0
 def tearDown(self):
     public_storage.delete(self.img_path)
Пример #28
0
 def remove_signed_file(self):
     if public_storage.exists(self.signed_file_path):
         public_storage.delete(self.signed_file_path)
Пример #29
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)
Пример #30
0
 def tearDown(self):
     public_storage.delete(self.latest_file.file_path)
Пример #31
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)
Пример #32
0
 def tearDown(self):
     public_storage.delete(self.latest_file.file_path)
Пример #33
0
 def destroy(self, request, *args, **kwargs):
     obj = self.get_object()
     if getattr(obj, "image_hash", None):
         public_storage.delete(obj.image_path(self.image_suffix))
         obj.update(**{self.hash_field: None})
     return Response(status=status.HTTP_204_NO_CONTENT)
Пример #34
0
 def destroy(self, request, *args, **kwargs):
     obj = self.get_object()
     if getattr(obj, 'image_hash', None):
         public_storage.delete(obj.image_path(self.image_suffix))
         obj.update(**{self.hash_field: None})
     return Response(status=status.HTTP_204_NO_CONTENT)