def testMinAvailableSpaceDeleteOldest(self):
        
        acc = []
        for i in range(30*2**10):
            acc.append("aaaaaaaaaa") 
        content1 = "".join(acc) #a 300K string
        
        totalFreeSpace = osutils.getfreespace(self.path1) / 1024.0
        minAvailableSpace = totalFreeSpace - 316 #enough space for the first content
        self.undertest = DiskManager(minAvailableSpace, RES_DIR)
        
        config = {"maxDiskUsage" : -1, 
                  "diskPolicy" : DISK_FULL_DELETE_SOME | DELETE_OLDEST_FIRST,
                  "encoding" : "utf-8"}
        
        self.undertest.registerDir(self.path1,config)
        
        self.undertest.writeContent(self.path1, "test1.txt", content1)
        
        expectedPath =os.path.join(self.path1,"test1.txt")
        self.assertTrue(os.path.isfile(expectedPath))


        content2 = "".join(acc[0:(6*2**10)-1]) #60KB string
        #the next write should be rejected
        res = self.undertest.writeContent(self.path1, "test2.txt", content2)
        self.assertTrue(res)
        unexpectedPath =os.path.join(self.path1,"test1.txt")
        self.assertFalse(os.path.exists(unexpectedPath))
        expectedPath = os.path.join(self.path1,"test2.txt")
        self.assertTrue(os.path.isfile(expectedPath))
 def testMinAvailableSpaceReject(self):
     totalFreeSpace = osutils.getfreespace(self.path1) / 1024.0
     minAvailableSpace = totalFreeSpace - 16.0 #enough space for the first content
     self.undertest = DiskManager(minAvailableSpace, RES_DIR)
     self.undertest.registerDir(self.path1) #using default config
     content1 = "Some Content\n\taaa\n"
     
     self.undertest.writeContent(self.path1, "test1.txt", content1)
     
     expectedPath =os.path.join(self.path1,"test1.txt")
     self.assertTrue(os.path.isfile(expectedPath))
     
     with codecs.open(expectedPath, "rb", "utf-8") as toRead:
         readContent = toRead.read()
     
     self.assertEquals(content1,readContent)
     
     acc = []
     for i in range(10*2**10):
         acc.append("aaaaaaaaaa") 
     content2 = "".join(acc) #a 100K string
     #the next write should be rejected
     self.assertRaises(DiskManagerException, self.undertest.writeContent,
                       self.path1, "test2.txt", content2)
     unexpectedPath =os.path.join(self.path1,"test2.txt")
     self.assertFalse(os.path.exists(unexpectedPath))
 def get_free_space(self):
     if not self.registered:
         return 0
     try:
         freespace = getfreespace(self.torrent_dir)
         return freespace
     except:
         print >> sys.stderr, "meta: cannot get free space of", self.torrent_dir
         print_exc()
         return 0
 def get_free_space(self):
     if not self.registered:
         return 0
     try:
         freespace = getfreespace(self.torrent_dir)
         return freespace
     except:
         print >> sys.stderr, "meta: cannot get free space of", self.torrent_dir
         print_exc()
         return 0
Exemple #5
0
 def _get_free_space(self):
     """
     Retrieves current free disk space.
     """
     try:
         freespace = getfreespace(self._baseDir) / 1024.0
         return freespace 
     except:
         print >> sys.stderr, "cannot get free space of", self._baseDir
         print_exc()
         return 0