2017-09-20 06:27:25 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# Install.py tool to download, unpack, build, and link to the LATTE library
|
|
|
|
# used to automate the steps described in the README file in this dir
|
|
|
|
|
|
|
|
from __future__ import print_function
|
2018-06-28 04:52:28 +08:00
|
|
|
import sys,os,re,subprocess,hashlib
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
|
|
|
help = """
|
|
|
|
Syntax from src dir: make lib-latte args="-b"
|
2018-04-11 23:20:39 +08:00
|
|
|
or: make lib-latte args="-p /usr/local/latte"
|
|
|
|
or: make lib-latte args="-m gfortran"
|
2018-06-26 04:58:49 +08:00
|
|
|
or: make lib-latte args="-b -v 1.2.1"
|
2018-04-11 23:20:39 +08:00
|
|
|
|
2017-09-20 06:27:25 +08:00
|
|
|
Syntax from lib dir: python Install.py -b
|
2018-04-11 23:20:39 +08:00
|
|
|
or: python Install.py -p /usr/local/latte
|
|
|
|
or: python Install.py -m gfortran
|
2018-06-26 04:58:49 +08:00
|
|
|
or: python Install.py -v 1.2.1 -b
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
specify one or more options, order does not matter
|
|
|
|
|
|
|
|
-b = download and build the LATTE library
|
|
|
|
-p = specify folder of existing LATTE installation
|
|
|
|
-m = copy Makefile.lammps.suffix to Makefile.lammps
|
2018-06-28 04:52:28 +08:00
|
|
|
-v = set version of LATTE library to download and set up (default = 1.2.1)
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
make lib-latte args="-b -m gfortran" # download/build in lib/latte
|
|
|
|
make lib-latte args="-p $HOME/latte" # use existing LATTE installation
|
|
|
|
"""
|
|
|
|
|
|
|
|
# settings
|
|
|
|
|
2018-06-26 04:58:49 +08:00
|
|
|
version = '1.2.1'
|
2017-09-20 06:27:25 +08:00
|
|
|
|
2018-06-28 04:52:28 +08:00
|
|
|
# known checksums for different LATTE versions. used to validate the download.
|
|
|
|
checksums = { \
|
|
|
|
'1.1.0' : '533635721ee222d0ed2925a18fb5b294', \
|
|
|
|
'1.2.0' : '68bf0db879da5e068a71281020239ae7', \
|
2018-07-23 22:35:40 +08:00
|
|
|
'1.2.1' : '85ac414fdada2d04619c8f936344df14', \
|
2018-06-28 04:52:28 +08:00
|
|
|
}
|
|
|
|
|
2017-09-20 06:27:25 +08:00
|
|
|
# print error message or help
|
|
|
|
|
|
|
|
def error(str=None):
|
|
|
|
if not str: print(help)
|
|
|
|
else: print("ERROR",str)
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# expand to full path name
|
|
|
|
# process leading '~' or relative path
|
|
|
|
|
|
|
|
def fullpath(path):
|
|
|
|
return os.path.abspath(os.path.expanduser(path))
|
|
|
|
|
|
|
|
def which(program):
|
|
|
|
def is_exe(fpath):
|
|
|
|
return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
|
|
|
|
|
|
|
|
fpath, fname = os.path.split(program)
|
|
|
|
if fpath:
|
|
|
|
if is_exe(program):
|
|
|
|
return program
|
|
|
|
else:
|
|
|
|
for path in os.environ["PATH"].split(os.pathsep):
|
|
|
|
path = path.strip('"')
|
|
|
|
exe_file = os.path.join(path, program)
|
|
|
|
if is_exe(exe_file):
|
|
|
|
return exe_file
|
|
|
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
def geturl(url,fname):
|
|
|
|
success = False
|
|
|
|
|
|
|
|
if which('curl') != None:
|
|
|
|
cmd = 'curl -L -o "%s" %s' % (fname,url)
|
|
|
|
try:
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
success = True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("Calling curl failed with: %s" % e.output.decode('UTF-8'))
|
|
|
|
|
|
|
|
if not success and which('wget') != None:
|
|
|
|
cmd = 'wget -O "%s" %s' % (fname,url)
|
|
|
|
try:
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
success = True
|
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
|
print("Calling wget failed with: %s" % e.output.decode('UTF-8'))
|
|
|
|
|
|
|
|
if not success:
|
|
|
|
error("Failed to download source code with 'curl' or 'wget'")
|
|
|
|
return
|
|
|
|
|
2018-06-28 04:52:28 +08:00
|
|
|
def checkmd5sum(md5sum,fname):
|
|
|
|
with open(fname,'rb') as fh:
|
|
|
|
m = hashlib.md5()
|
|
|
|
while True:
|
|
|
|
data = fh.read(81920)
|
|
|
|
if not data:
|
|
|
|
break
|
|
|
|
m.update(data)
|
|
|
|
fh.close()
|
|
|
|
return m.hexdigest() == md5sum
|
|
|
|
|
2017-09-20 06:27:25 +08:00
|
|
|
# parse args
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
nargs = len(args)
|
|
|
|
if nargs == 0: error()
|
|
|
|
|
|
|
|
homepath = "."
|
|
|
|
|
|
|
|
buildflag = False
|
|
|
|
pathflag = False
|
|
|
|
suffixflag = False
|
|
|
|
linkflag = True
|
|
|
|
|
|
|
|
iarg = 0
|
|
|
|
while iarg < nargs:
|
|
|
|
if args[iarg] == "-p":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
lattedir = fullpath(args[iarg+1])
|
|
|
|
pathflag = True
|
|
|
|
iarg += 2
|
|
|
|
elif args[iarg] == "-b":
|
|
|
|
buildflag = True
|
|
|
|
iarg += 1
|
|
|
|
elif args[iarg] == "-m":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
suffix = args[iarg+1]
|
|
|
|
suffixflag = True
|
|
|
|
iarg += 2
|
2018-04-11 23:20:39 +08:00
|
|
|
elif args[iarg] == "-v":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
version = args[iarg+1]
|
|
|
|
iarg += 2
|
2017-09-20 06:27:25 +08:00
|
|
|
else: error()
|
|
|
|
|
2018-04-11 23:20:39 +08:00
|
|
|
homedir = "LATTE-%s" % version
|
|
|
|
|
2017-09-20 06:27:25 +08:00
|
|
|
if (buildflag and pathflag):
|
|
|
|
error("Cannot use -b and -p flag at the same time")
|
|
|
|
|
|
|
|
if buildflag:
|
2018-04-11 23:20:39 +08:00
|
|
|
url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version
|
2017-09-20 06:27:25 +08:00
|
|
|
lattepath = fullpath(homepath)
|
|
|
|
lattedir = "%s/%s" % (lattepath,homedir)
|
|
|
|
|
|
|
|
if pathflag:
|
|
|
|
if not os.path.isdir(lattedir): error("LATTE path does not exist")
|
|
|
|
|
|
|
|
# download and unpack LATTE tarball
|
|
|
|
|
|
|
|
if buildflag:
|
|
|
|
print("Downloading LATTE ...")
|
2018-04-11 23:20:39 +08:00
|
|
|
geturl(url,"LATTE.tar.gz")
|
2017-09-20 06:27:25 +08:00
|
|
|
|
2018-06-28 04:52:28 +08:00
|
|
|
# verify downloaded archive integrity via md5 checksum, if known.
|
|
|
|
if version in checksums:
|
|
|
|
if not checkmd5sum(checksums[version],'LATTE.tar.gz'):
|
|
|
|
error("Checksum for LATTE library does not match")
|
|
|
|
|
2018-06-26 07:43:31 +08:00
|
|
|
print("Unpacking LATTE ...")
|
2017-09-20 06:27:25 +08:00
|
|
|
if os.path.exists(lattedir):
|
|
|
|
cmd = 'rm -rf "%s"' % lattedir
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2018-04-11 23:20:39 +08:00
|
|
|
cmd = 'cd "%s"; tar zxvf LATTE.tar.gz' % lattepath
|
2017-09-20 06:27:25 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2018-04-11 23:20:39 +08:00
|
|
|
os.remove("%s/LATTE.tar.gz" % lattepath)
|
2017-09-20 06:27:25 +08:00
|
|
|
|
|
|
|
# build LATTE
|
|
|
|
|
|
|
|
if buildflag:
|
|
|
|
print("Building LATTE ...")
|
|
|
|
cmd = 'cd "%s"; make' % lattedir
|
|
|
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
print(txt.decode('UTF-8'))
|
|
|
|
|
|
|
|
# create 3 links in lib/latte to LATTE dirs
|
|
|
|
# do this -b or -p is set
|
2018-06-28 04:52:28 +08:00
|
|
|
|
2017-09-20 06:27:25 +08:00
|
|
|
if buildflag or pathflag:
|
|
|
|
print("Creating links to LATTE files")
|
|
|
|
if os.path.isfile("includelink") or os.path.islink("includelink"):
|
|
|
|
os.remove("includelink")
|
|
|
|
if os.path.isfile("liblink") or os.path.islink("liblink"):
|
|
|
|
os.remove("liblink")
|
2017-09-26 07:37:37 +08:00
|
|
|
if os.path.isfile("filelink.o") or os.path.islink("filelink.o"):
|
|
|
|
os.remove("filelink.o")
|
2017-09-20 06:27:25 +08:00
|
|
|
cmd = 'ln -s "%s/src" includelink' % lattedir
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
cmd = 'ln -s "%s" liblink' % lattedir
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
2017-09-26 07:37:37 +08:00
|
|
|
cmd = 'ln -s "%s/src/latte_c_bind.o" filelink.o' % lattedir
|
2017-09-20 06:27:25 +08:00
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
|
|
|
|
|
|
|
# copy Makefile.lammps.suffix to Makefile.lammps
|
|
|
|
|
|
|
|
if suffixflag:
|
|
|
|
print("Creating Makefile.lammps")
|
|
|
|
if os.path.exists("Makefile.lammps.%s" % suffix):
|
|
|
|
cmd = 'cp Makefile.lammps.%s Makefile.lammps' % suffix
|
|
|
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|