Пример #1
0
    def checkUploadFinalize(self, event):
        """
        Check if an upload will fit within a quota restriction before
        finalizing it.  If it doesn't, discard it.

        :param event: event record.
        """
        upload = event.info
        quotaInfo = self._checkUploadSize(upload)
        if quotaInfo:
            # Delete the upload
            self.model('upload').cancelUpload(upload)
            raise GirderException(
                'Upload exceeded file storage quota (need %s, only %s '
                'available - used %s out of %s)' %
                (formatSize(quotaInfo['sizeNeeded']),
                 formatSize(quotaInfo['quotaLeft']),
                 formatSize(quotaInfo['quotaUsed']),
                 formatSize(quotaInfo['fileSizeQuota'])),
                'user_quota.upload-exceeds-quota')
Пример #2
0
    def checkUploadStart(self, event):
        """
        Check if an upload will fit within a quota restriction.  This is before
        the upload occurs, but since multiple uploads can be started
        concurrently, we also have to check when the upload is being completed.

        :param event: event record.
        """
        if '_id' in event.info:
            return
        quotaInfo = self._checkUploadSize(event.info)
        if quotaInfo:
            raise GirderException(
                'Upload would exceed file storage quota (need %s, only %s '
                'available - used %s out of %s)' %
                (formatSize(quotaInfo['sizeNeeded']),
                 formatSize(quotaInfo['quotaLeft']),
                 formatSize(quotaInfo['quotaUsed']),
                 formatSize(quotaInfo['fileSizeQuota'])),
                'user_quota.upload-exceeds-quota')
Пример #3
0
 def testFormatSize(self):
     """
     Test the formatSize function
     """
     testList = [
         (1000, '1000 B'),
         (10000, '10000 B'),
         (20000, '19.53 kB'),
         (200000, '195.3 kB'),
         (2000000, '1.907 MB'),
         ]
     for testItem in testList:
         self.assertEqual(testItem[1], formatSize(testItem[0]))
Пример #4
0
 def testFormatSize(self):
     """
     Test the formatSize function
     """
     testList = [
         (1000, '1000 B'),
         (10000, '10000 B'),
         (20000, '19.53 kB'),
         (200000, '195.3 kB'),
         (2000000, '1.907 MB'),
     ]
     for testItem in testList:
         self.assertEqual(testItem[1], formatSize(testItem[0]))