示例#1
0
    def handle_noargs(self, **options):
        #check if rabbitmq is working
        try:
            connection = pika.BlockingConnection(
                pika.ConnectionParameters(settings.RABBITMQ_SERVER))
        except:
            logger.critical(
                "We are experiencing a connection problem and cannot perform uploads for now. Please try again later."
            )

        logger.info("Uploading file to s3...")
        upload_to_s3(FILE_KEY, FILE_LOCATION)
        logger.info("Upload process successful.")

        logger.info("Enqueuing slug to rabbitmq...")
        enqueue(FILE_KEY)
        logger.info("Enqueue process successful.")

        #should indicate that video was uploaded and is stored in s3
        logger.info("Checking if video is already in s3 (should be there)...")
        check_from_s3(FILE_KEY)
        #check if an expiring url can be generated, similar to how Screenbird gets url for video playing
        logger.info("Checking generation of expiring url...")
        try:
            conn = Connection(is_secure=True)
            url = conn.generate_object_expiring_url(FILE_KEY)
            if not url:
                logger.critical("Failed to generate expiring url.")
                raise Exception
        except:
            logger.critical("Failed to check for an expiring url.")
        logger.info("Expiring url successfully generated.")

        logger.info("Deleting file from s3...")
        delete_from_s3(FILE_KEY)
        logger.info("Delete process successful.")

        #should indicate that video is not anymore stored in s3 because of the delete
        logger.info(
            "Checking if video is still in s3 (should NOT be there anymore)..."
        )
        check_from_s3(FILE_KEY)
示例#2
0
    def handle_noargs(self, **options):
        #check if rabbitmq is working
        try:
            connection = pika.BlockingConnection(pika.ConnectionParameters(settings.RABBITMQ_SERVER))
        except:
            logger.critical("We are experiencing a connection problem and cannot perform uploads for now. Please try again later.")
        
        logger.info("Uploading file to s3...")
        upload_to_s3(FILE_KEY, FILE_LOCATION)
        logger.info("Upload process successful.")
        
        logger.info("Enqueuing slug to rabbitmq...")
        enqueue(FILE_KEY)
        logger.info("Enqueue process successful.")

        #should indicate that video was uploaded and is stored in s3
        logger.info("Checking if video is already in s3 (should be there)...")
        check_from_s3(FILE_KEY)
        #check if an expiring url can be generated, similar to how Screenbird gets url for video playing
        logger.info("Checking generation of expiring url...")
        try:
            conn = Connection(is_secure=True)
            url = conn.generate_object_expiring_url(FILE_KEY)
            if not url:
                logger.critical("Failed to generate expiring url.")
                raise Exception
        except:
            logger.critical("Failed to check for an expiring url.")
        logger.info("Expiring url successfully generated.")
           
        logger.info("Deleting file from s3...")         
        delete_from_s3(FILE_KEY)
        logger.info("Delete process successful.")
        
        #should indicate that video is not anymore stored in s3 because of the delete
        logger.info("Checking if video is still in s3 (should NOT be there anymore)...")
        check_from_s3(FILE_KEY)
示例#3
0
    def delete(self, *args, **kwargs):
        """
        If the video to be deleted is a part of a channel, reassign the
        video owner to be the admin, send the appropriate notification, and
        he can then choose whether to delete or keep the video.

        In addition, updates the uploader's total upload time.

        """
        from videos.utils import get_video_length
        if self.uploader:
            try:
                profile = self.uploader.userprofile
            except UserProfile.DoesNotExist:
                return
            else:
                total_time = profile.total_upload_time
                total_time = total_time - self.video_duration
                profile.total_upload_time = str(total_time)
                profile.save()

            if self.channel and self.uploader != self.channel.owner:
                # Videos part of a channel, when about to be deleted,
                # will instead be reassigned to the channel owner to
                # act upon.
                self.uploader = self.channel.owner
                self.save()
                self._send_video_delete_notification()
                return False
        if settings.PUSH_TO_S3:
            delete_from_s3('%s_tmp' % self.slug)
            delete_from_s3(self.slug)
            delete_from_s3('%s__mobile' % self.slug)
        else:
            video_path = os.path.join(settings.MEDIA_ROOT, 'tmp',
                                      '%s.mp4' % self.slug)
            mobile_video_path = os.path.join(settings.MEDIA_ROOT, 'tmp',
                                             '%s__mobile.mp4' % self.slug)
            os.remove(video_path)
            os.remove(mobile_video_path)
        super(Video, self).delete(*args, **kwargs)
示例#4
0
    def delete(self, *args, **kwargs):
        """
        If the video to be deleted is a part of a channel, reassign the
        video owner to be the admin, send the appropriate notification, and
        he can then choose whether to delete or keep the video.

        In addition, updates the uploader's total upload time.

        """
        from videos.utils import get_video_length
        if self.uploader:
            try:
                profile = self.uploader.userprofile
            except UserProfile.DoesNotExist:
                return
            else:
                total_time = profile.total_upload_time
                total_time = total_time - self.video_duration
                profile.total_upload_time = str(total_time)
                profile.save()

            if self.channel and self.uploader != self.channel.owner:
                # Videos part of a channel, when about to be deleted,
                # will instead be reassigned to the channel owner to
                # act upon.
                self.uploader = self.channel.owner
                self.save()
                self._send_video_delete_notification()
                return False
        if settings.PUSH_TO_S3:
            delete_from_s3('%s_tmp' %self.slug)
            delete_from_s3(self.slug)
            delete_from_s3('%s__mobile' % self.slug)
        else:
            video_path = os.path.join(settings.MEDIA_ROOT, 'tmp', '%s.mp4' % self.slug)
            mobile_video_path = os.path.join(settings.MEDIA_ROOT, 'tmp', '%s__mobile.mp4' % self.slug)
            os.remove(video_path)
            os.remove(mobile_video_path)
        super(Video, self).delete(*args, **kwargs)