Ejemplo n.º 1
0
 def _download_package(self, id):
     """downloads the specified package, if the download was successfull, it checks the package's md5 checksum
     versus the one stored in the package info for integretiy, and if succefull, dispatches a success message
     """
     package = self._available_packages.get(id)
     if package is None:
         raise PackageNotFound()
     try:
         downloadPath = os.path.join(self._path_manager.tmpPath,
                                     package.file)
         yield DownloaderWithProgress.download(url=package.downloadUrl,
                                               destination=downloadPath,
                                               object=package,
                                               refChecksum=package.fileHash)
         package.downloaded = True
         #update.installPath=self._addon_path
         self._send_signal("package_download_succeeded", package)
         log.msg("Successfully downloaded package ",
                 package.name,
                 system="Package Manager",
                 logLevel=logging.DEBUG)
     except Exception as inst:
         self._send_signal("package_download_failed", package)
         log.msg("Failed to download package",
                 package.name,
                 " error:",
                 inst,
                 system="Package Manager",
                 logLevel=logging.CRITICAL)
Ejemplo n.º 2
0
 def refresh_packageList(self):
     """Fetches the remote package list, downloads it, and if there were any changes, packages
     the in memory package list accordingly
     """
     log.msg("checking for new packages : time", time.time(), logLevel=logging.CRITICAL)
     packageInfoPath = os.path.join(self._path_manager.tmpPath, "packages.txt") 
     try:
         yield DownloaderWithProgress.download(url=self.package_list_url, destination=packageInfoPath)
         self._parse_packageListFile()
     except Exception as inst:
         log.msg("Failed to download package master list: error:", inst, system="Package Manager", logLevel=logging.CRITICAL)
Ejemplo n.º 3
0
 def _download_package(self, id):
     """downloads the specified package, if the download was successfull, it checks the package's md5 checksum
     versus the one stored in the package info for integretiy, and if succefull, dispatches a success message
     """
     package = self._available_packages.get(id)
     if package is None:
         raise PackageNotFound()
     try:
         downloadPath = os.path.join(self._path_manager.tmpPath,package.file)  
         yield DownloaderWithProgress.download(url = package.downloadUrl, destination= downloadPath, object=package, refChecksum=package.fileHash)
         package.downloaded = True
         #update.installPath=self._addon_path
         self._send_signal("package_download_succeeded", package)
         log.msg("Successfully downloaded package ",package.name,system="Package Manager",logLevel=logging.DEBUG)
     except Exception as inst:
         self._send_signal("package_download_failed", package)
         log.msg("Failed to download package",package.name," error:",inst,system="Package Manager",logLevel=logging.CRITICAL)
Ejemplo n.º 4
0
 def refresh_packageList(self):
     """Fetches the remote package list, downloads it, and if there were any changes, packages
     the in memory package list accordingly
     """
     log.msg("checking for new packages : time",
             time.time(),
             logLevel=logging.CRITICAL)
     packageInfoPath = os.path.join(self._path_manager.tmpPath,
                                    "packages.txt")
     try:
         yield DownloaderWithProgress.download(url=self.package_list_url,
                                               destination=packageInfoPath)
         self._parse_packageListFile()
     except Exception as inst:
         log.msg("Failed to download package master list: error:",
                 inst,
                 system="Package Manager",
                 logLevel=logging.CRITICAL)
Ejemplo n.º 5
0
class DownloaderTest(unittest.TestCase):
    def setUp(self):
        self._mockServerport = 8765
        self._fileServePath = ""
        self._testFileName = "TestFile.txt"
        self._downloadUrl = "http://localhost:%i/%s" % (self._mockServerport,
                                                        self._testFileName)

        self._downloader = DownloaderWithProgress()
        self._path_manager = PathManager()
        self._path_manager.tmpPath = "tmp"
        if not os.path.exists("tmp"):
            os.makedirs("tmp")
        try:
            if not os.path.exists(self._fileServePath):
                os.makedirs(self._fileServePath)
        except:
            pass

        self._start_mock_file_server(self._fileServePath)
        self._downloadPath = os.path.join(self._path_manager.tmpPath,
                                          self._testFileName)
        self._testFilePath = os.path.join(self._fileServePath,
                                          self._testFileName)
        self._write_mock_file(self._testFilePath)

    def tearDown(self):
        self._stop_mock_file_server()
        os.remove(self._testFileName)
        if os.path.exists("tmp"):
            shutil.rmtree("tmp")
        if os.path.exists(self._fileServePath):
            shutil.rmtree(self._fileServePath)

    @defer.inlineCallbacks
    def test_download_file(self):
        yield self._downloader.download(url=self._downloadUrl,
                                        destination=self._downloadPath)
        expFilePath = self._downloadPath
        self.assertTrue(os.path.exists(expFilePath))

    @defer.inlineCallbacks
    def test_download_file_with_progress_update(self):
        obsUpdatableObject = MockUpdatableObject()
        expUpdatableObject = MockUpdatableObject(100)
        expFilePath = self._downloadPath

        yield self._downloader.download(url=self._downloadUrl,
                                        destination=self._downloadPath,
                                        object=obsUpdatableObject)

        self.assertEquals(obsUpdatableObject, expUpdatableObject)
        self.assertTrue(os.path.exists(expFilePath))

    @defer.inlineCallbacks
    def test_download_file_with_checksum(self):
        obsUpdatableObject = MockUpdatableObject()
        expFilePath = self._downloadPath
        yield self._downloader.download(
            url=self._downloadUrl,
            destination=self._downloadPath,
            object=obsUpdatableObject,
            refChecksum="18c0864b36d60f6036bf8eeab5c1fe7d")
        self.assertTrue(os.path.exists(expFilePath))

    def test_download_file_with_checksumError(self):
        obsUpdatableObject = MockUpdatableObject()
        d = self._downloader.download(
            url=self._downloadUrl,
            destination=self._downloadPath,
            object=obsUpdatableObject,
            refChecksum="18c0864b36d60f6036bf8eeab5c1fe7f")
        return self.assertFailure(d, Exception)

    def _start_mock_file_server(self, fileServePath):
        self._handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        self.httpd = SocketServer.TCPServer(("", self._mockServerport),
                                            self._handler)
        print("serving on port %i" % self._mockServerport)
        self._t = Thread(target=self.httpd.serve_forever).start()

    def _stop_mock_file_server(self):
        self.httpd.shutdown()
        self.httpd.server_close()
        print("stopped serving on port %i" % self._mockServerport)

    def _write_mock_file(self, path):
        f = open(path, "w")
        f.write("somecontent")
        f.close()
Ejemplo n.º 6
0
class DownloaderTest(unittest.TestCase):    
    def setUp(self):
        self._mockServerport = 8765
        self._fileServePath = ""
        self._testFileName = "TestFile.txt"
        self._downloadUrl = "http://localhost:%i/%s" %(self._mockServerport,self._testFileName)
        
        self._downloader = DownloaderWithProgress()
        self._path_manager = PathManager()
        self._path_manager.tmpPath = "tmp"
        if not os.path.exists("tmp"):
            os.makedirs("tmp")       
        try: 
            if not os.path.exists(self._fileServePath):
                os.makedirs(self._fileServePath)
        except:pass  
        
        self._start_mock_file_server(self._fileServePath)
        self._downloadPath = os.path.join(self._path_manager.tmpPath,self._testFileName)
        self._testFilePath = os.path.join(self._fileServePath,self._testFileName)
        self._write_mock_file(self._testFilePath)
        
    def tearDown(self):
        self._stop_mock_file_server()
        os.remove(self._testFileName)
        if os.path.exists("tmp"):
            shutil.rmtree("tmp")
        if os.path.exists(self._fileServePath): 
            shutil.rmtree(self._fileServePath)
            
    @defer.inlineCallbacks
    def test_download_file(self):
        yield self._downloader.download(url = self._downloadUrl ,destination = self._downloadPath)
        expFilePath = self._downloadPath
        self.assertTrue(os.path.exists(expFilePath))
            
    @defer.inlineCallbacks
    def test_download_file_with_progress_update(self):
        obsUpdatableObject = MockUpdatableObject()
        expUpdatableObject = MockUpdatableObject(100)
        expFilePath = self._downloadPath
        
        yield self._downloader.download(url = self._downloadUrl ,destination = self._downloadPath, object = obsUpdatableObject)
        
        self.assertEquals(obsUpdatableObject,expUpdatableObject)
        self.assertTrue(os.path.exists(expFilePath))
        
    @defer.inlineCallbacks
    def test_download_file_with_checksum(self):
        obsUpdatableObject = MockUpdatableObject()
        expFilePath = self._downloadPath        
        yield self._downloader.download(url = self._downloadUrl ,destination = self._downloadPath, object = obsUpdatableObject, refChecksum = "18c0864b36d60f6036bf8eeab5c1fe7d")
        self.assertTrue(os.path.exists(expFilePath))
    
    def test_download_file_with_checksumError(self):
        obsUpdatableObject = MockUpdatableObject()
        d = self._downloader.download(url = self._downloadUrl ,destination = self._downloadPath, object = obsUpdatableObject, refChecksum = "18c0864b36d60f6036bf8eeab5c1fe7f")
        return self.assertFailure(d, Exception)
        
    def _start_mock_file_server(self,fileServePath):
        self._handler = SimpleHTTPServer.SimpleHTTPRequestHandler
        self.httpd = SocketServer.TCPServer(("", self._mockServerport), self._handler)
        print ("serving on port %i" %self._mockServerport)
        self._t=Thread(target=self.httpd.serve_forever).start()    
            
    def _stop_mock_file_server(self):
        self.httpd.shutdown()
        self.httpd.server_close()
        print ("stopped serving on port %i" %self._mockServerport)
        
    def _write_mock_file(self,path):
        f = open(path,"w") 
        f.write("somecontent")
        f.close()