more Install.py refactoring
This commit is contained in:
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess,shutil
|
import sys,os,re,subprocess,shutil
|
||||||
|
sys.path.append('..')
|
||||||
|
from install_helpers import error,fullpath,which,geturl
|
||||||
|
|
||||||
# help message
|
# help message
|
||||||
|
|
||||||
@ -51,64 +53,13 @@ https://openkim.org/kim-api
|
|||||||
in the "What is in the KIM API source package?" section
|
in the "What is in the KIM API source package?" section
|
||||||
"""
|
"""
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# parse args
|
# parse args
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
nargs = len(args)
|
nargs = len(args)
|
||||||
if nargs == 0: error()
|
if nargs == 0: error(help=help)
|
||||||
|
|
||||||
thisdir = os.environ['PWD']
|
thisdir = fullpath('.')
|
||||||
version = "kim-api-v1.9.5"
|
version = "kim-api-v1.9.5"
|
||||||
|
|
||||||
buildflag = False
|
buildflag = False
|
||||||
@ -120,7 +71,7 @@ pathflag = False
|
|||||||
iarg = 0
|
iarg = 0
|
||||||
while iarg < len(args):
|
while iarg < len(args):
|
||||||
if args[iarg] == "-v":
|
if args[iarg] == "-v":
|
||||||
if iarg+2 > len(args): error()
|
if iarg+2 > len(args): error(help=help)
|
||||||
version = args[iarg+1]
|
version = args[iarg+1]
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-b":
|
elif args[iarg] == "-b":
|
||||||
@ -130,14 +81,14 @@ while iarg < len(args):
|
|||||||
buildflag = False
|
buildflag = False
|
||||||
iarg += 1
|
iarg += 1
|
||||||
elif args[iarg] == "-p":
|
elif args[iarg] == "-p":
|
||||||
if iarg+2 > len(args): error()
|
if iarg+2 > len(args): error(help=help)
|
||||||
kimdir = fullpath(args[iarg+1])
|
kimdir = fullpath(args[iarg+1])
|
||||||
pathflag = True
|
pathflag = True
|
||||||
buildflag = False
|
buildflag = False
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-a":
|
elif args[iarg] == "-a":
|
||||||
addflag = True
|
addflag = True
|
||||||
if iarg+2 > len(args): error()
|
if iarg+2 > len(args): error(help=help)
|
||||||
addmodelname = args[iarg+1]
|
addmodelname = args[iarg+1]
|
||||||
if addmodelname == "everything":
|
if addmodelname == "everything":
|
||||||
buildflag = True
|
buildflag = True
|
||||||
@ -147,9 +98,8 @@ while iarg < len(args):
|
|||||||
elif args[iarg] == "-vv":
|
elif args[iarg] == "-vv":
|
||||||
verboseflag = True
|
verboseflag = True
|
||||||
iarg += 1
|
iarg += 1
|
||||||
else: error()
|
else: error(help=help)
|
||||||
|
|
||||||
thisdir = os.path.abspath(thisdir)
|
|
||||||
url = "https://s3.openkim.org/kim-api/%s.txz" % version
|
url = "https://s3.openkim.org/kim-api/%s.txz" % version
|
||||||
|
|
||||||
# set KIM API directory
|
# set KIM API directory
|
||||||
@ -157,7 +107,7 @@ url = "https://s3.openkim.org/kim-api/%s.txz" % version
|
|||||||
if pathflag:
|
if pathflag:
|
||||||
if not os.path.isdir(kimdir):
|
if not os.path.isdir(kimdir):
|
||||||
print("\nkim-api is not installed at %s" % kimdir)
|
print("\nkim-api is not installed at %s" % kimdir)
|
||||||
error()
|
error(help=help)
|
||||||
|
|
||||||
# configure LAMMPS to use existing kim-api installation
|
# configure LAMMPS to use existing kim-api installation
|
||||||
with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile:
|
with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile:
|
||||||
@ -247,7 +197,7 @@ if addflag:
|
|||||||
|
|
||||||
if not os.path.isdir(kimdir):
|
if not os.path.isdir(kimdir):
|
||||||
print("\nkim-api is not installed")
|
print("\nkim-api is not installed")
|
||||||
error()
|
error(help=help)
|
||||||
|
|
||||||
# download single model
|
# download single model
|
||||||
cmd = '%s/bin/kim-api-v1-collections-management install system %s' % (kimdir.decode("UTF-8"), addmodelname)
|
cmd = '%s/bin/kim-api-v1-collections-management install system %s' % (kimdir.decode("UTF-8"), addmodelname)
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess,hashlib,shutil
|
import sys,os,re,subprocess,hashlib,shutil
|
||||||
|
sys.path.append('..')
|
||||||
|
from install_helpers import error,get_cpus,fullpath,which,geturl,checkmd5sum
|
||||||
|
|
||||||
# help message
|
# help message
|
||||||
|
|
||||||
@ -42,74 +44,11 @@ checksums = { \
|
|||||||
'2.5b' : 'e341bdef469be1da058b8a0b97a3db22', \
|
'2.5b' : 'e341bdef469be1da058b8a0b97a3db22', \
|
||||||
}
|
}
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
# parse args
|
# parse args
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
nargs = len(args)
|
nargs = len(args)
|
||||||
if nargs == 0: error()
|
if nargs == 0: error(help=help)
|
||||||
|
|
||||||
homepath = "."
|
homepath = "."
|
||||||
|
|
||||||
@ -121,22 +60,22 @@ linkflag = True
|
|||||||
iarg = 0
|
iarg = 0
|
||||||
while iarg < nargs:
|
while iarg < nargs:
|
||||||
if args[iarg] == "-v":
|
if args[iarg] == "-v":
|
||||||
if iarg+2 > nargs: error()
|
if iarg+2 > nargs: error(help=help)
|
||||||
version = args[iarg+1]
|
version = args[iarg+1]
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-p":
|
elif args[iarg] == "-p":
|
||||||
if iarg+2 > nargs: error()
|
if iarg+2 > nargs: error(help=help)
|
||||||
plumedpath = fullpath(args[iarg+1])
|
plumedpath = fullpath(args[iarg+1])
|
||||||
pathflag = True
|
pathflag = True
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-m":
|
elif args[iarg] == "-m":
|
||||||
if iarg+2 > nargs: error()
|
if iarg+2 > nargs: error(help=help)
|
||||||
mode = args[iarg+1]
|
mode = args[iarg+1]
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-b":
|
elif args[iarg] == "-b":
|
||||||
buildflag = True
|
buildflag = True
|
||||||
iarg += 1
|
iarg += 1
|
||||||
else: error()
|
else: error(help=help)
|
||||||
|
|
||||||
homepath = fullpath(homepath)
|
homepath = fullpath(homepath)
|
||||||
homedir = "%s/plumed2" % (homepath)
|
homedir = "%s/plumed2" % (homepath)
|
||||||
@ -178,14 +117,14 @@ if buildflag:
|
|||||||
|
|
||||||
# build plumed
|
# build plumed
|
||||||
print("Building plumed ...")
|
print("Building plumed ...")
|
||||||
try:
|
n_cpus = get_cpus()
|
||||||
import multiprocessing
|
|
||||||
n_cpus = multiprocessing.cpu_count()
|
|
||||||
except:
|
|
||||||
n_cpus = 1
|
|
||||||
cmd = 'cd %s/plumed-%s; ./configure --prefix=%s --enable-static-patch ; make -j%d ; make install' % (homepath,version,homedir,n_cpus)
|
cmd = 'cd %s/plumed-%s; ./configure --prefix=%s --enable-static-patch ; make -j%d ; make install' % (homepath,version,homedir,n_cpus)
|
||||||
|
try:
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
print(txt.decode('UTF-8'))
|
print(txt.decode('UTF-8'))
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# create 2 links in lib/plumed to plumed2 installation dir
|
# create 2 links in lib/plumed to plumed2 installation dir
|
||||||
|
|
||||||
|
|||||||
@ -5,6 +5,8 @@
|
|||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess,shutil
|
import sys,os,re,subprocess,shutil
|
||||||
|
sys.path.append('..')
|
||||||
|
from install_helpers import error,fullpath,which,geturl
|
||||||
|
|
||||||
# help message
|
# help message
|
||||||
|
|
||||||
@ -33,60 +35,6 @@ version = "scafacos-1.0.1"
|
|||||||
url = "https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz"
|
url = "https://github.com/scafacos/scafacos/releases/download/v1.0.1/scafacos-1.0.1.tar.gz"
|
||||||
#url = "https://gigamove.rz.rwth-aachen.de/d/id/CTzyApN76MXMJ6/dd/100" % version
|
#url = "https://gigamove.rz.rwth-aachen.de/d/id/CTzyApN76MXMJ6/dd/100" % version
|
||||||
|
|
||||||
# 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)
|
|
||||||
print("Wget command: %s" % cmd)
|
|
||||||
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
|
|
||||||
|
|
||||||
# parse args
|
# parse args
|
||||||
|
|
||||||
args = sys.argv[1:]
|
args = sys.argv[1:]
|
||||||
@ -101,18 +49,18 @@ linkflag = True
|
|||||||
iarg = 0
|
iarg = 0
|
||||||
while iarg < nargs:
|
while iarg < nargs:
|
||||||
if args[iarg] == "-v":
|
if args[iarg] == "-v":
|
||||||
if iarg+2 > nargs: error()
|
if iarg+2 > nargs: error(help=help)
|
||||||
version = args[iarg+1]
|
version = args[iarg+1]
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-p":
|
elif args[iarg] == "-p":
|
||||||
if iarg+2 > nargs: error()
|
if iarg+2 > nargs: error(help=help)
|
||||||
scafacospath = fullpath(args[iarg+1])
|
scafacospath = fullpath(args[iarg+1])
|
||||||
pathflag = True
|
pathflag = True
|
||||||
iarg += 2
|
iarg += 2
|
||||||
elif args[iarg] == "-b":
|
elif args[iarg] == "-b":
|
||||||
buildflag = True
|
buildflag = True
|
||||||
iarg += 1
|
iarg += 1
|
||||||
else: error()
|
else: error(help=help)
|
||||||
|
|
||||||
homepath = fullpath(homepath)
|
homepath = fullpath(homepath)
|
||||||
homedir = "%s/%s" % (homepath,version)
|
homedir = "%s/%s" % (homepath,version)
|
||||||
@ -145,9 +93,14 @@ if buildflag:
|
|||||||
|
|
||||||
if buildflag:
|
if buildflag:
|
||||||
print("Building Scafacos ...")
|
print("Building Scafacos ...")
|
||||||
cmd = 'cd "%s"; ./configure --prefix="`pwd`/build" --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m --with-internal-fftw --with-internal-pfft --with-internal-pnfft CC=mpicc FC=mpif90 CXX=mpicxx F77= > log.txt; make -j; make install' % homedir
|
n_cpu = get_gpus()
|
||||||
|
cmd = 'cd "%s"; ./configure --prefix="%s/build" --disable-doc --enable-fcs-solvers=fmm,p2nfft,direct,ewald,p3m --with-internal-fftw --with-internal-pfft --with-internal-pnfft CC=mpicc FC=mpif90 CXX=mpicxx F77=; make -j%d; make install' % (homedir,homedir,n_cpu)
|
||||||
|
try:
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
print(txt.decode('UTF-8'))
|
print(txt.decode('UTF-8'))
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
# create 2 links in lib/scafacos to Scafacos include/lib dirs
|
# create 2 links in lib/scafacos to Scafacos include/lib dirs
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user