#!/usr/bin/env python3 import shutil import json import os from lib.ui import progressbar, bordered, underlined, print_welcome from lib.shell import get_from_command from lib.toolchain import get_compiler_version, get_mpi_version, set_toolchain from lib.sort import sort_libs_by_dependencies from lib.installer import install_lib from lib.init import init, check_python_version SCRIPT_VERSION = "v0.4" # check if Python >=3.3.0 is used check_python_version() # initialization by argparser arg_namespace, args = init() # extract known arguments from argparse namespace prefix = arg_namespace.prefix config_dir = arg_namespace.config src_dir = arg_namespace.src work_dir = arg_namespace.work keep_work = arg_namespace.keep_work compiler = arg_namespace.compiler mpi = arg_namespace.mpi build_threads = arg_namespace.threads verbose = arg_namespace.verbose # extract libraries and versions selected for installation selected_libs = [] ignore_names = ["config", "mpi", "compiler", "prefix", "src", "work", "threads", "verbose", "version"] for lib_name in args: if lib_name not in ignore_names and "version" not in lib_name: install = getattr(arg_namespace, lib_name) if install: version = getattr(arg_namespace, lib_name+"_version") config_file = config_dir + "/" + lib_name + ".json" with open(config_file, 'r') as cf: data = json.load(cf) data['version'] = version selected_libs.append(data) # set up install directory name compiler_version = get_compiler_version(compiler) mpi_version = get_mpi_version(mpi) inst_str = "inst-"+compiler + "_" + compiler_version + "_" + mpi + "_" + mpi_version inst_dir = prefix + "/" + inst_str # set up mpi wrappers and environment variables cc, cxx, fc = set_toolchain(compiler, mpi) # set up library install order by dependencies sorted_libs = sort_libs_by_dependencies(selected_libs) # print welcome screen print_welcome(SCRIPT_VERSION, compiler, compiler_version, mpi, mpi_version, inst_dir, sorted_libs) # install selected libraries if len(sorted_libs) > 0: for lib in sorted_libs: install_lib(lib, src_dir, work_dir, inst_dir, cc, cxx, fc, build_threads, verbose) print(bordered("ALL INSTALLS COMPLETED SUCCESSFULLY\nPlease add "+inst_dir+" to your environment")) else: print("NO LIBRARIES SELECTED FOR INSTALLATION") # cleanup if (not keep_work and os.path.exists(work_dir)): print("Cleaning up work directory...") shutil.rmtree(work_dir) print("Done.") print("\n")