Example #1
0
 def get_quota_usage(self, format="json", **kwargs):
     user, sMessages, fMessages, quotaMB, quotaUsedMB = (cherrypy.session.get("user"),[], [], 0, 0)
     try:
         quotaMB, quotaUsage = 0,0
         if cherrypy.session.get("current_role") is not None:
             quotaMB = cherrypy.session.get("current_role").quota
             quotaUsage = FileService.get_role_quota_usage_bytes(cherrypy.session.get("current_role").id)
         else:
             quotaMB = user.quota
             quotaUsage = FileService.get_user_quota_usage_bytes(user.id)
         quotaUsedMB = int(quotaUsage) / 1024 / 1024
     except Exception, e:
         fMessages.append(str(e))
 def get_quota_usage(self, format="json", **kwargs):
     user, sMessages, fMessages, quotaMB, quotaUsedMB = (
         cherrypy.session.get("user"), [], [], 0, 0)
     try:
         quotaMB, quotaUsage = 0, 0
         if cherrypy.session.get("current_role") is not None:
             quotaMB = cherrypy.session.get("current_role").quota
             quotaUsage = FileService.get_role_quota_usage_bytes(
                 cherrypy.session.get("current_role").id)
         else:
             quotaMB = user.quota
             quotaUsage = FileService.get_user_quota_usage_bytes(user.id)
         quotaUsedMB = int(quotaUsage) / 1024 / 1024
     except Exception, e:
         fMessages.append(str(e))
        if (fileSizeMB * 2) >= vaultSpaceFreeMB:
            cherrypy.log.error(
                "[system] [upload] [File vault is running out of space and cannot fit this file. Remaining Space is %s MB, fileSizeBytes is %s]"
                % (vaultSpaceFreeMB, fileSizeBytes))
            fMessages.append(
                "The server doesn't have enough space left on its drive to fit this file. The administrator has been notified."
            )
            raise cherrypy.HTTPError(
                413,
                "The server doesn't have enough space left on its drive to fit this file. The administrator has been notified."
            )
        quotaSpaceRemainingBytes = 0
        if role is not None:
            quotaSpaceRemainingBytes = (
                role.quota * 1024 *
                1024) - FileService.get_role_quota_usage_bytes(role.id)
        else:
            quotaSpaceRemainingBytes = (
                user.quota * 1024 *
                1024) - FileService.get_user_quota_usage_bytes(user.id)
        if fileSizeBytes > quotaSpaceRemainingBytes:
            fMessages.append(
                "File size is larger than your quota will accommodate")
            raise cherrypy.HTTPError(
                413, "File size is larger than your quota will accommodate")

        #The server won't respond to additional user requests (polling) until we release the lock
        cherrypy.session.release_lock()

        newFile = File()
        newFile.size = fileSizeBytes
Example #4
0
            lcHDRS[key.lower()] = val
        try:
            fileSizeBytes = int(lcHDRS['content-length'])
        except KeyError, ke:
            fMessages.append("Request must have a valid content length")
            raise cherrypy.HTTPError(411, "Request must have a valid content length")
        fileSizeMB = ((fileSizeBytes/1024)/1024)
        vaultSpaceFreeMB, vaultCapacityMB = FileService.get_vault_usage()
        
        if (fileSizeMB*2) >= vaultSpaceFreeMB:
            cherrypy.log.error("[system] [upload] [File vault is running out of space and cannot fit this file. Remaining Space is %s MB, fileSizeBytes is %s]" % (vaultSpaceFreeMB, fileSizeBytes))
            fMessages.append("The server doesn't have enough space left on its drive to fit this file. The administrator has been notified.")
            raise cherrypy.HTTPError(413, "The server doesn't have enough space left on its drive to fit this file. The administrator has been notified.")
        quotaSpaceRemainingBytes = 0
        if role is not None:
            quotaSpaceRemainingBytes = (role.quota*1024*1024) - FileService.get_role_quota_usage_bytes(role.id)
        else:
            quotaSpaceRemainingBytes = (user.quota*1024*1024) - FileService.get_user_quota_usage_bytes(user.id)
        if fileSizeBytes > quotaSpaceRemainingBytes:
            fMessages.append("File size is larger than your quota will accommodate")
            raise cherrypy.HTTPError(413, "File size is larger than your quota will accommodate")

        #The server won't respond to additional user requests (polling) until we release the lock
        cherrypy.session.release_lock()

        newFile = File()
        newFile.size = fileSizeBytes
        #Get the file name
        fileName, tempFileName = None,None
        if fileName is None and lcHDRS.has_key('x-file-name'):
            fileName = lcHDRS['x-file-name']