libinstaller/libinstaller

106 lines
4.0 KiB
Python
Executable File

#!/usr/bin/env python3
import shutil
import os
import glob
from lib.ui import bordered, print_welcome
from lib.toolchain import get_compiler_version, get_mpi_version, set_toolchain
from lib.dependency import sort_libs_by_dependencies, load_selected_libs
from lib.installer import install_lib
from lib.init import init, check_python_version
SCRIPT_VERSION = "v0.9"
# 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
separate_lib64 = arg_namespace.separate_lib64
disable_shared = arg_namespace.disable_shared
install_all_libs = arg_namespace.all
ignore_deps = arg_namespace.ignore_deps
# extract libraries and versions selected for installation
selected_libs = load_selected_libs(config_dir, arg_namespace, args, install_all_libs, ignore_deps)
'''
selected_libs = []
if install_all_libs:
for config_file in glob.glob(config_dir+"/*.json"):
data = load_lib_data(config_file)
#with open(cf, 'r') as f:
#data = json.load(f)
data['version'] = data['default version']
selected_libs.append(data)
else:
ignore_names = ["config", "mpi", "compiler", "prefix", "src", "work", "keep_work", "threads", "verbose", "version", "disable_shared"]
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"
data = load_lib_data(config_file)
data['version'] = data['default version']
selected_libs.append(data)
#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, build_threads, disable_shared, inst_dir, sorted_libs)
# install selected libraries
if len(sorted_libs) > 0:
# add install dir to environment
os.environ["LIBRARY_PATH"] = inst_dir + "/lib" + os.pathsep + inst_dir + "/lib64" + os.pathsep + os.environ["LIBRARY_PATH"]
os.environ["LD_LIBRARY_PATH"] = inst_dir + "/lib" + os.pathsep + inst_dir + "/lib64" + os.pathsep + os.environ["LD_LIBRARY_PATH"]
# install libraries
for lib in sorted_libs:
install_lib(lib, src_dir, work_dir, inst_dir, cc, cxx, fc, build_threads, disable_shared, verbose)
print(bordered("ALL INSTALLS COMPLETED SUCCESSFULLY\nPlease add "+inst_dir+" to your environment"))
else:
print("NO LIBRARIES SELECTED FOR INSTALLATION")
# create symbolic links
if not separate_lib64:
lib_dir = inst_dir + "/lib"
lib64_dir = inst_dir + "/lib64"
if os.path.exists(lib_dir) and os.path.exists(lib64_dir):
print("Creating symbolic links...")
for file in glob.glob(lib64_dir+"/*.*"):
if not os.path.exists(file.replace("lib64","lib")):
os.symlink(file, file.replace("lib64","lib"))
# cleanup
if (not keep_work and os.path.exists(work_dir)):
print("Cleaning up work directory...")
shutil.rmtree(work_dir)
print("Done.")
print("\n")