def bin_directory(exists, create): if create: click.echo("Creating {}".format(idaes.bin_directory)) idaes._create_bin_dir() elif exists: click.echo(os.path.exists(idaes.bin_directory)) else: click.echo(idaes.bin_directory)
def download_binaries(url=None, verbose=False): """ Download IDAES solvers and libraries and put them in the right location. Need to supply either local or url argument. Args: url (str): a url to download binary files to install files Returns: None """ if verbose: _log.setLevel(idaeslog.DEBUG) idaes._create_lib_dir() idaes._create_bin_dir() solvers_tar = os.path.join(idaes.bin_directory, "idaes-solvers.tar.gz") libs_tar = os.path.join(idaes.lib_directory, "idaes-lib.tar.gz") fd = FileDownloader() arch = fd.get_sysinfo() if url is not None: if not url.endswith("/"): c = "/" else: c = "" solvers_from = c.join( [url, "idaes-solvers-{}-{}.tar.gz".format(arch[0], arch[1])]) libs_from = c.join( [url, "idaes-lib-{}-{}.tar.gz".format(arch[0], arch[1])]) _log.debug("URLs \n {}\n {}\n {}".format(url, solvers_from, libs_from)) _log.debug("Destinations \n {}\n {}".format(solvers_tar, libs_tar)) if arch[0] == 'darwin': raise Exception('Mac OSX currently unsupported') fd.set_destination_filename(solvers_tar) fd.get_binary_file(solvers_from) fd.set_destination_filename(libs_tar) fd.get_binary_file(libs_from) else: raise Exception("Must provide a location to download binaries") _log.debug("Extracting files in {}".format(idaes.bin_directory)) with tarfile.open(solvers_tar, 'r') as f: f.extractall(idaes.bin_directory) _log.debug("Extracting files in {}".format(idaes.lib_directory)) with tarfile.open(libs_tar, 'r') as f: f.extractall(idaes.lib_directory)
def download_binaries( release=None, url=None, insecure=False, cacert=None, verbose=False, platform="auto", nochecksum=False, library_only=False, no_download=False, to_path=None): """ Download IDAES solvers and libraries and put them in the right location. Need to supply either local or url argument. Args: url (str): a url to download binary files to install files to_path: for testing only, an alternate subdirectory of the idaes data directory for a test binary install. Returns: None """ if verbose: _log.setLevel(idaeslog.DEBUG) if no_download: nochecksum = True # set the locations to download files to, to_path is an alternate # subdirectory of idaes.data_directory that can optionally be used to test # this function without interfereing with anything else. It's a subdirectory # of the data directory because that should be a safe place to store some # test files. if to_path is None: to_path = idaes.bin_directory else: to_path = os.path.join(idaes.data_directory, to_path) idaes._create_bin_dir(to_path) fd, arch = _get_file_downloader(insecure, cacert) platform = _get_platform(fd, platform, arch) url, checksum = _get_release_url_and_checksum( fd, to_path, release, url, nochecksum) # Set the binary file destinations solvers_tar = os.path.join(to_path, "idaes-solvers.tar.gz") libs_tar = os.path.join(to_path, "idaes-lib.tar.gz") # Set the binary file download locations solvers_from = "/".join([url, f"idaes-solvers-{platform}-{arch[1]}.tar.gz"]) libs_from = "/".join([url, f"idaes-lib-{platform}-{arch[1]}.tar.gz"]) if no_download: d = { "release": release, "platform": platform, "bits": arch[1], "libs_only": library_only, "libs_from": libs_from, "libs_to": libs_tar, } if not library_only: d["solvers_from"] = solvers_from d["solvers_to"] = solvers_tar return d if not library_only: _download_package( fd, "solvers", frm=solvers_from, to=solvers_tar, platform=platform) _download_package( fd, "libraries", frm=libs_from, to=libs_tar, platform=platform) # If release checksum is not empty, nochecksum opt allows hash to be ignored if checksum: # Check solvers package hash if not library_only: hash_s = _hash(solvers_tar) _log.debug("Solvers Hash {}".format(hash_s)) if checksum.get( f"idaes-solvers-{platform}-{arch[1]}.tar.gz", "") != hash_s: raise Exception("Solver package hash does not match expected") # Check libraries package hash hash_l = _hash(libs_tar) _log.debug("Libs Hash {}".format(hash_l)) if checksum.get(f"idaes-lib-{platform}-{arch[1]}.tar.gz", "") != hash_l: raise Exception("Library package hash does not match expected") # Extract solvers if not library_only: _log.debug("Extracting files in {}".format(idaes.bin_directory)) with tarfile.open(solvers_tar, 'r') as f: f.extractall(to_path) # Extract libraries _log.debug("Extracting files in {}".format(idaes.bin_directory)) with tarfile.open(libs_tar, 'r') as f: f.extractall(to_path)
def download_binaries(release=None, url=None, verbose=False, platform="auto"): """ Download IDAES solvers and libraries and put them in the right location. Need to supply either local or url argument. Args: url (str): a url to download binary files to install files Returns: None """ if verbose: _log.setLevel(idaeslog.DEBUG) idaes._create_bin_dir() solvers_tar = os.path.join(idaes.bin_directory, "idaes-solvers.tar.gz") libs_tar = os.path.join(idaes.bin_directory, "idaes-lib.tar.gz") fd = FileDownloader() arch = fd.get_sysinfo() if arch[1] != 64: _log.error("IDAES Extensions currently only supports 64bit Python.") raise RuntimeError( "IDAES Extensions currently only supports 64bit Python.") if platform == "auto": platform = arch[0] if platform == "linux": linux_dist = fd.get_os_version().replace(".", "") if linux_dist in idaes.config.known_binary_platform: platform = linux_dist if platform not in idaes.config.known_binary_platform: raise Exception("Unknow platform {}".format(platform)) if platform in idaes.config.binary_platform_map: platform = idaes.config.binary_platform_map[platform] checksum = {} if release is not None: # if a release is specified it takes precedence over a url url = "/".join([_release_base_url, release]) # if we're downloading an official release check checksum check_to = os.path.join(idaes.bin_directory, f"sha256sum_{release}.txt") check_from = f"https://raw.githubusercontent.com/IDAES/idaes-ext/main/releases/sha256sum_{release}.txt" _log.debug("Getting release {}\n checksum file {}".format( release, check_from)) fd.set_destination_filename(check_to) fd.get_binary_file(check_from) with open(check_to, 'r') as f: for i in range(1000): line = f.readline(1000) if line == "": break line = line.split(sep=" ") checksum[line[1].strip()] = line[0].strip() if url is not None: if not url.endswith("/"): c = "/" else: c = "" solvers_from = c.join( [url, "idaes-solvers-{}-{}.tar.gz".format(platform, arch[1])]) libs_from = c.join( [url, "idaes-lib-{}-{}.tar.gz".format(platform, arch[1])]) _log.debug("URLs \n {}\n {}\n {}".format(url, solvers_from, libs_from)) _log.debug("Destinations \n {}\n {}".format(solvers_tar, libs_tar)) if platform == 'darwin': raise Exception('Mac OSX currently unsupported') fd.set_destination_filename(solvers_tar) fd.get_binary_file(solvers_from) fd.set_destination_filename(libs_tar) fd.get_binary_file(libs_from) else: raise Exception("Must provide a location to download binaries") if checksum: # if you are downloading a release and not a specific URL verify checksum fn_s = "idaes-solvers-{}-{}.tar.gz".format(platform, arch[1]) fn_l = "idaes-lib-{}-{}.tar.gz".format(platform, arch[1]) hash_s = _hash(solvers_tar) hash_l = _hash(libs_tar) _log.debug("Solvers Hash {}".format(hash_s)) _log.debug("Libs Hash {}".format(hash_l)) if checksum.get(fn_s, "") != hash_s: raise Exception("Solver files hash does not match expected") if checksum.get(fn_l, "") != hash_l: raise Exception("Library files hash does not match expected") _log.debug("Extracting files in {}".format(idaes.bin_directory)) with tarfile.open(solvers_tar, 'r') as f: f.extractall(idaes.bin_directory) _log.debug("Extracting files in {}".format(idaes.bin_directory)) with tarfile.open(libs_tar, 'r') as f: f.extractall(idaes.bin_directory)
def download_binaries( release=None, url=None, insecure=False, cacert=None, verbose=False, platform="auto", nochecksum=False, library_only=False, no_download=False, extras_only=False, extra=(), to_path=None, alt_path=None, ): """ Download IDAES solvers and libraries and put them in the right location. Need to supply either local or url argument. Args: url (str): a url to download binary files to install files to_path: for testing only, an alternate subdirectory of the idaes data directory for a test binary install. Returns: None """ if verbose: _log.setLevel(idaeslog.DEBUG) if no_download: nochecksum = True # set the locations to download files to, to_path is an alternate # subdirectory of idaes.data_directory that can optionally be used to test # this function without interfereing with anything else. It's a subdirectory # of the data directory because that should be a safe place to store some # test files. if alt_path is not None: to_path = os.path.abspath(alt_path) if to_path is None: to_path = idaes.bin_directory else: to_path = os.path.join(idaes.data_directory, to_path) idaes._create_bin_dir(to_path) fd, arch = _get_file_downloader(insecure, cacert) platform = _get_platform(fd, platform, arch) url, checksum = _get_release_url_and_checksum(fd, to_path, release, url, nochecksum) # Set the binary file destinations pname = [] ptar = [] ftar = [] furl = [] def _add_pack(name): f = f"idaes-{name}-{platform}-{arch[1]}.tar.gz" ftar.append(f) ptar.append(os.path.join(to_path, f)) pname.append(name) furl.append("/".join([url, f])) for e in extra: if e not in extra_binaries: _log.warning(f"Unknown extra package {e}, not installed.") continue if platform not in extra_binaries[e]: _log.warning( f"Extra package {e} not available for {platform}, not installed." ) continue _add_pack( e) # you have to explicitly ask for extras so assume you want if not extras_only: _add_pack("lib") if not library_only and not extras_only: _add_pack("solvers") if no_download: d = { "release": release, "platform": platform, "bits": arch[1], } for n, p, u in zip(pname, ptar, furl): d[u] = p return d # download packages for n, p, u in zip(pname, ptar, furl): _download_package(fd, n, frm=u, to=p, platform=platform) # If release checksum is not empty, nochecksum opt allows hash to be ignored if checksum: for n, p, f in zip(pname, ptar, ftar): hash_l = _hash(p) _log.debug(f"{n} Hash {hash_l}") if checksum.get(f, "") != hash_l: raise Exception(f"{n} hash does not match expected") # Extract solvers for n, p in zip(pname, ptar): _log.debug(f"Extracting files in {p} to {to_path}") with tarfile.open(p, 'r') as f: f.extractall(to_path)