Ejemplo n.º 1
0
 def test_fail_interrupted_download_to_file_if_no_progress(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content, chunk_size=0)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config=_ConfigMock())
     with self.assertRaisesRegexp(ConanException, r"Download failed"):
         downloader.download("fake_url", file_path=self.target)
Ejemplo n.º 2
0
 def test_succeed_download_to_file_if_not_interrupted(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config=_ConfigMock())
     downloader.download("fake_url", file_path=self.target)
     actual_content = load(self.target, binary=True)
     self.assertEqual(expected_content, actual_content)
Ejemplo n.º 3
0
 def test_fail_download_to_memory_if_interrupted(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content, chunk_size=4)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config=_ConfigMock())
     with self.assertRaisesRegexp(ConanException,
                                  r"Transfer interrupted before complete"):
         downloader.download("fake_url", file_path=None)
Ejemplo n.º 4
0
 def test_fail_interrupted_download_to_file_if_no_progress(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content, chunk_size=0)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config_retry=0,
                                 config_retry_wait=0)
     with pytest.raises(ConanException, match=r"Download failed"):
         downloader.download("fake_url", file_path=self.target)
Ejemplo n.º 5
0
 def test_resume_download_to_file_if_interrupted(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content, chunk_size=4)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config_retry=0,
                                 config_retry_wait=0)
     downloader.download("fake_url", file_path=self.target)
     actual_content = load(self.target, binary=True)
     self.assertEqual(expected_content, actual_content)
Ejemplo n.º 6
0
 def test_fail_download_to_memory_if_interrupted(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content, chunk_size=4)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config_retry=0,
                                 config_retry_wait=0)
     with pytest.raises(ConanException,
                        match=r"Transfer interrupted before complete"):
         downloader.download("fake_url", file_path=None)
Ejemplo n.º 7
0
def _process_download(config, cache, output, requester):
    with tmp_config_install_folder(cache) as tmp_folder:
        output.info("Trying to download  %s" % _hide_password(config.uri))
        zippath = os.path.join(tmp_folder, os.path.basename(config.uri))
        try:
            downloader = FileDownloader(requester=requester, output=output, verify=config.verify_ssl,
                                        config_retry=None, config_retry_wait=None)
            downloader.download(url=config.uri, file_path=zippath)
            _process_zip_file(config, zippath, cache, output, tmp_folder, first_remove=True)
        except Exception as e:
            raise ConanException("Error while installing config from %s\n%s" % (config.uri, str(e)))
Ejemplo n.º 8
0
 def test_fail_interrupted_download_if_server_not_accepting_ranges(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content,
                               chunk_size=4,
                               accept_ranges=False)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config=_ConfigMock())
     with self.assertRaisesRegexp(ConanException,
                                  r"Incorrect Content-Range header"):
         downloader.download("fake_url", file_path=self.target)
Ejemplo n.º 9
0
 def test_fail_interrupted_download_if_server_not_accepting_ranges(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content,
                               chunk_size=4,
                               accept_ranges=False)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config_retry=0,
                                 config_retry_wait=0)
     with pytest.raises(ConanException,
                        match=r"Incorrect Content-Range header"):
         downloader.download("fake_url", file_path=self.target)
Ejemplo n.º 10
0
 def test_download_with_compressed_content_and_smaller_content_length(self):
     expected_content = b"some data"
     echo_header = {
         "Content-Encoding": "gzip",
         "Content-Length": len(expected_content) - 1
     }
     requester = MockRequester(expected_content, echo_header=echo_header)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config=_ConfigMock())
     downloader.download("fake_url", file_path=self.target)
     actual_content = load(self.target, binary=True)
     self.assertEqual(expected_content, actual_content)
Ejemplo n.º 11
0
    def _get_path(self, url, path):
        urls = self._get_file_to_url_dict(url)

        def is_dir(the_path):
            if the_path == ".":
                return True
            for _the_file in urls:
                if the_path == _the_file:
                    return False
                elif _the_file.startswith(the_path):
                    return True
            raise NotFoundException("The specified path doesn't exist")

        if is_dir(path):
            ret = []
            for the_file in urls:
                if path == "." or the_file.startswith(path):
                    tmp = the_file[len(path) - 1:].split("/", 1)[0]
                    if tmp not in ret:
                        ret.append(tmp)
            return sorted(ret)
        else:
            downloader = FileDownloader(self.requester, None, self.verify_ssl,
                                        self._config.retry,
                                        self._config.retry_wait)
            auth, _ = self._file_server_capabilities(urls[path])
            content = downloader.download(urls[path], auth=auth)

            return decode_text(content)
Ejemplo n.º 12
0
 def test_succeed_download_to_memory_if_not_interrupted(self):
     expected_content = b"some data"
     requester = MockRequester(expected_content)
     downloader = FileDownloader(requester=requester,
                                 output=self.out,
                                 verify=None,
                                 config_retry=0,
                                 config_retry_wait=0)
     actual_content = downloader.download("fake_url", file_path=None)
     self.assertEqual(expected_content, actual_content)
Ejemplo n.º 13
0
def run_downloader(requester, output, verify, config, user_download=False, use_cache=True, **kwargs):
    downloader = FileDownloader(requester=requester, output=output, verify=verify, config=config)
    if use_cache and config.download_cache:
        if config.remote_cache:
            downloader = CachedFileDownloader(remote_cache=config.remote_cache, file_downloader=downloader,
                                              user_download=user_download)
        else:
            downloader = CachedFileDownloader(download_cache=config.download_cache, file_downloader=downloader,
                                              user_download=user_download)
    return downloader.download(**kwargs)
Ejemplo n.º 14
0
def run_downloader(requester,
                   output,
                   verify,
                   retry,
                   retry_wait,
                   download_cache,
                   user_download=False,
                   **kwargs):
    downloader = FileDownloader(requester=requester,
                                output=output,
                                verify=verify,
                                config_retry=retry,
                                config_retry_wait=retry_wait)
    if download_cache:
        downloader = CachedFileDownloader(download_cache,
                                          downloader,
                                          user_download=user_download)
    return downloader.download(**kwargs)