Esempio n. 1
0
 def download(self,url="", destination="", object=None, refChecksum = None):
     for attempt in range(0,self._max_download_attempts):
         try:
             download = self._createDownloader(url=url, file = destination, element = object)
             self._currentDownloads[url] = download
             yield download.deferred
             if refChecksum is not None:
                 isSameChecksum = yield ChecksumTools.compare_hash(refChecksum, destination) 
                 if not isSameChecksum:
                     raise Exception("File checksum mismatch")
             defer.returnValue(None)
         except Exception as inst:
             print ("Failed to download file at attempt %i because of error %s "%(attempt,str(inst)))
             
     del self._currentDownloads[url]
     if os.path.exists(destination):
         os.remove(destination)
     raise Exception("Failed to download file at %s after %i attempts" %(url, self._max_download_attempts))
Esempio n. 2
0
 def test_compare_hash_false(self):        
     inputHash = "12d0864b36d60f6036bf8eeab5c1feqsd"
     obsCompare = yield ChecksumTools.compare_hash(inputHash, self._testFileName)
     self.assertFalse(obsCompare)
Esempio n. 3
0
 def test_compare_hash(self):
     inputHash = "18c0864b36d60f6036bf8eeab5c1fe7d"
     obsCompare = yield ChecksumTools.compare_hash(inputHash, self._testFileName)
     self.assertTrue(obsCompare)
Esempio n. 4
0
 def test_generate_hash(self):
     expChecksum = "18c0864b36d60f6036bf8eeab5c1fe7d"
     obsChecksum = yield ChecksumTools.generate_hash(filePath=self._testFileName)
     self.assertEquals(obsChecksum,expChecksum)
Esempio n. 5
0
 def test_compare_hash_false(self):
     inputHash = "12d0864b36d60f6036bf8eeab5c1feqsd"
     obsCompare = yield ChecksumTools.compare_hash(inputHash,
                                                   self._testFileName)
     self.assertFalse(obsCompare)
Esempio n. 6
0
 def test_compare_hash(self):
     inputHash = "18c0864b36d60f6036bf8eeab5c1fe7d"
     obsCompare = yield ChecksumTools.compare_hash(inputHash,
                                                   self._testFileName)
     self.assertTrue(obsCompare)
Esempio n. 7
0
 def test_generate_hash(self):
     expChecksum = "18c0864b36d60f6036bf8eeab5c1fe7d"
     obsChecksum = yield ChecksumTools.generate_hash(
         filePath=self._testFileName)
     self.assertEquals(obsChecksum, expChecksum)