def build(self): download_url = "https://cmake.org/files/v{}/{}".format( self.cmake_major_minor, self.cmake_zip_name) self.output.warn("Downloading '{}'...".format(download_url)) tools.download(download_url, self.cmake_zip_name) tools.unzip(self.cmake_zip_name) os.unlink(self.cmake_zip_name)
def build(self): appimage_name = "linuxdeployqt-%s-x86_64.AppImage" % self.version[1] url = "https://github.com/probonopd/linuxdeployqt/releases/download/%s/%s" % (self.version[1], appimage_name) self.output.warn("Downloading %s: %s" % (appimage_name, url)) tools.download(url, "linuxdeployqt") # Add execute permission st = os.stat('linuxdeployqt') os.chmod("linuxdeployqt", st.st_mode | stat.S_IEXEC)
def source(self): zip_name = f"bzip2-{self.version}.tar.gz" url = f"https://bintray.com/conan/Sources/download_file?" \ f"file_path={zip_name}" download(url, zip_name) check_md5(zip_name, "00b516f4704d4a7cb50a1d97e6e8e15b") unzip(zip_name) os.unlink(zip_name)
def _process_download(item, client_cache, output, tmp_folder, verify_ssl, requester): output.info("Trying to download %s" % _hide_password(item)) zippath = os.path.join(tmp_folder, "config.zip") try: tools.download(item, zippath, out=output, verify=verify_ssl, requester=requester) _process_zip_file(zippath, client_cache, output, tmp_folder, remove=True) except Exception as e: raise ConanException("Error while installing config from %s\n%s" % (item, str(e)))
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, "config.zip") try: tools.download(config.uri, zippath, out=output, verify=config.verify_ssl, requester=requester) _process_zip_file(config, zippath, cache, output, tmp_folder, remove=True) except Exception as e: raise ConanException("Error while installing config from %s\n%s" % (config.uri, str(e)))
def source(self): zip_name = "zlib-%s.tar.gz" % self.version tools.download( "http://downloads.sourceforge.net/project/libpng/zlib/%s/%s" % (self.version, zip_name), zip_name) tools.unzip(zip_name) os.unlink(zip_name) files.rmdir("%s/contrib" % self.ZIP_FOLDER_NAME) if self.settings.os != "Windows": self.run("chmod +x ./%s/configure" % self.ZIP_FOLDER_NAME)
def get_version(suffix): nasm_zip_name = "%s-%s.zip" % (self.nasm_folder_name, suffix) tools.download( "http://www.nasm.us/pub/nasm/releasebuilds/" "%s/%s/%s" % (self.version, suffix, nasm_zip_name), nasm_zip_name) self.output.warn("Downloading nasm: " "http://www.nasm.us/pub/nasm/releasebuilds" "/%s/%s/%s" % (self.version, suffix, nasm_zip_name)) tools.unzip(nasm_zip_name) os.unlink(nasm_zip_name)
def build(self): if self.settings.arch_build == "x86": arch = "i686" elif self.settings.arch_build == "x86_64": arch = "x86_64" appimage_name = "appimagetool-%s.AppImage" % arch url = "https://github.com/AppImage/AppImageKit/releases/download/%s/%s" % ( self.version[1:], appimage_name) self.output.warn("Downloading %s: %s" % (appimage_name, url)) tools.download(url, "appimagetool") # Add execute permission st = os.stat('appimagetool') os.chmod("appimagetool", st.st_mode | stat.S_IEXEC)
def download_retries_errors_test(self): out = TestBufferConanOutput() # Retry arguments override defaults with six.assertRaisesRegex(self, ConanException, "Error downloading"): tools.download("http://fakeurl3.es/nonexists", os.path.join(temp_folder(), "file.txt"), out=out, requester=requests, retry=2, retry_wait=1) self.assertEqual(str(out).count("Waiting 1 seconds to retry..."), 2) # Not found error with six.assertRaisesRegex(self, NotFoundException, "Not found: "): tools.download("http://google.es/FILE_NOT_FOUND", os.path.join(temp_folder(), "README.txt"), out=out, requester=requests, retry=2, retry_wait=0)
def download_unathorized_test(self, mock_config): http_server = StoppableThreadBottle() mock_config.return_value = ConfigMock() @http_server.server.get('/forbidden') def get_forbidden(): return HTTPError(403, "Access denied.") http_server.run_server() out = TestBufferConanOutput() dest = os.path.join(temp_folder(), "manual.html") # Not authorized with six.assertRaisesRegex(self, AuthenticationException, "403"): tools.download("http://localhost:%s/forbidden" % http_server.port, dest, requester=requests, out=out) http_server.stop()
def build(self): download_url = "http://releases.llvm.org/{}/{}".format(self.version, self.clang_zip_name) self.output.warn("Downloading '{}'...".format(download_url)) tools.download(download_url, self.clang_zip_name) tools.unzip(self.clang_zip_name) os.unlink(self.clang_zip_name)
def source(self): tar_file = f"v{self.version}.tar.gz" download(f"{self.url}/archive/{tar_file}", tar_file) unzip(tar_file) os.unlink(tar_file) shutil.move("imgui-{}".format(self.version), "imgui")
def download_retries_test(self): http_server = StoppableThreadBottle() with tools.chdir(tools.mkdir_tmp()): with open("manual.html", "w") as fmanual: fmanual.write("this is some content") manual_file = os.path.abspath("manual.html") from bottle import auth_basic @http_server.server.get("/manual.html") def get_manual(): return static_file(os.path.basename(manual_file), os.path.dirname(manual_file)) def check_auth(user, password): # Check user/password here return user == "user" and password == "passwd" @http_server.server.get('/basic-auth/<user>/<password>') @auth_basic(check_auth) def get_manual_auth(user, password): return static_file(os.path.basename(manual_file), os.path.dirname(manual_file)) http_server.run_server() out = TestBufferConanOutput() # Connection error # Default behaviour with six.assertRaisesRegex(self, ConanException, "Error downloading"): tools.download("http://fakeurl3.es/nonexists", os.path.join(temp_folder(), "file.txt"), out=out, requester=requests) self.assertEqual(str(out).count("Waiting 5 seconds to retry..."), 1) # Retry arguments override defaults with six.assertRaisesRegex(self, ConanException, "Error downloading"): tools.download("http://fakeurl3.es/nonexists", os.path.join(temp_folder(), "file.txt"), out=out, requester=requests, retry=2, retry_wait=1) self.assertEqual(str(out).count("Waiting 1 seconds to retry..."), 2) # Retry default values from the config class MockRequester(object): retry = 2 retry_wait = 0 def get(self, *args, **kwargs): return requests.get(*args, **kwargs) with six.assertRaisesRegex(self, ConanException, "Error downloading"): tools.download("http://fakeurl3.es/nonexists", os.path.join(temp_folder(), "file.txt"), out=out, requester=MockRequester()) self.assertEqual(str(out).count("Waiting 0 seconds to retry..."), 2) # Not found error with six.assertRaisesRegex(self, NotFoundException, "Not found: "): tools.download("http://google.es/FILE_NOT_FOUND", os.path.join(temp_folder(), "README.txt"), out=out, requester=requests, retry=2, retry_wait=0) # And OK dest = os.path.join(temp_folder(), "manual.html") tools.download("http://localhost:%s/manual.html" % http_server.port, dest, out=out, retry=3, retry_wait=0, requester=requests) self.assertTrue(os.path.exists(dest)) content = load(dest) # overwrite = False with self.assertRaises(ConanException): tools.download("http://localhost:%s/manual.html" % http_server.port, dest, out=out, retry=2, retry_wait=0, overwrite=False, requester=requests) # overwrite = True tools.download("http://localhost:%s/manual.html" % http_server.port, dest, out=out, retry=2, retry_wait=0, overwrite=True, requester=requests) self.assertTrue(os.path.exists(dest)) content_new = load(dest) self.assertEqual(content, content_new) # Not authorized with self.assertRaises(ConanException): tools.download("http://localhost:%s/basic-auth/user/passwd" % http_server.port, dest, overwrite=True, requester=requests, out=out) # Authorized tools.download("http://localhost:%s/basic-auth/user/passwd" % http_server.port, dest, auth=("user", "passwd"), overwrite=True, requester=requests, out=out) # Authorized using headers tools.download("http://localhost:%s/basic-auth/user/passwd" % http_server.port, dest, headers={"Authorization": "Basic dXNlcjpwYXNzd2Q="}, overwrite=True, requester=requests, out=out) http_server.stop()
def test_download_retries(self): http_server = StoppableThreadBottle() with tools.chdir(tools.mkdir_tmp()): with open("manual.html", "w") as fmanual: fmanual.write("this is some content") manual_file = os.path.abspath("manual.html") from bottle import auth_basic @http_server.server.get("/manual.html") def get_manual(): return static_file(os.path.basename(manual_file), os.path.dirname(manual_file)) def check_auth(user, password): # Check user/password here return user == "user" and password == "passwd" @http_server.server.get('/basic-auth/<user>/<password>') @auth_basic(check_auth) def get_manual_auth(user, password): return static_file(os.path.basename(manual_file), os.path.dirname(manual_file)) http_server.run_server() out = TestBufferConanOutput() dest = os.path.join(temp_folder(), "manual.html") tools.download("http://localhost:%s/manual.html" % http_server.port, dest, out=out, retry=3, retry_wait=0, requester=requests) self.assertTrue(os.path.exists(dest)) content = load(dest) # overwrite = False with self.assertRaises(ConanException): tools.download("http://localhost:%s/manual.html" % http_server.port, dest, out=out, retry=2, retry_wait=0, overwrite=False, requester=requests) # overwrite = True tools.download("http://localhost:%s/manual.html" % http_server.port, dest, out=out, retry=2, retry_wait=0, overwrite=True, requester=requests) self.assertTrue(os.path.exists(dest)) content_new = load(dest) self.assertEqual(content, content_new) # Not authorized with self.assertRaises(ConanException): tools.download("http://localhost:%s/basic-auth/user/passwd" % http_server.port, dest, overwrite=True, requester=requests, out=out, retry=0, retry_wait=0) # Authorized tools.download("http://localhost:%s/basic-auth/user/passwd" % http_server.port, dest, auth=("user", "passwd"), overwrite=True, requester=requests, out=out, retry=0, retry_wait=0) # Authorized using headers tools.download("http://localhost:%s/basic-auth/user/passwd" % http_server.port, dest, headers={"Authorization": "Basic dXNlcjpwYXNzd2Q="}, overwrite=True, requester=requests, out=out, retry=0, retry_wait=0) http_server.stop()