update Install.py for LATTE to use the argparse module

This commit is contained in:
Axel Kohlmeyer 2019-01-14 16:54:44 -05:00
parent 2604b60eb8
commit 659bec582e
1 changed files with 57 additions and 71 deletions

View File

@ -6,7 +6,23 @@
from __future__ import print_function
import sys,os,re,subprocess,shutil
sys.path.append('..')
from install_helpers import error,get_cpus,fullpath,which,geturl,checkmd5sum
from install_helpers import get_cpus,fullpath,geturl,checkmd5sum
from argparse import ArgumentParser
parser = ArgumentParser(prog='Install.py',
description="LAMMPS library build wrapper script")
# settings
version = '1.2.1'
suffix = 'gfortran'
# known checksums for different LATTE versions. used to validate the download.
checksums = { \
'1.1.0' : '533635721ee222d0ed2925a18fb5b294', \
'1.2.0' : '68bf0db879da5e068a71281020239ae7', \
'1.2.1' : '85ac414fdada2d04619c8f936344df14', \
}
# help message
@ -21,77 +37,50 @@ Syntax from lib dir: python Install.py -b
or: python Install.py -m gfortran
or: python Install.py -v 1.2.1 -b
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
-v = set version of LATTE library to download and set up (default = 1.2.1)
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
version = '1.2.1'
pgroup = parser.add_mutually_exclusive_group()
pgroup.add_argument("-b", "--build", action="store_true",
help="download and build the Eigen3 library")
pgroup.add_argument("-p", "--path",
help="specify folder of existing Eigen installation")
parser.add_argument("-m", "--machine", choices=['gfortran','ifort','linalg','serial','mpi'],
help="suffix of a Makefile.lammps.* file used for linking LAMMPS with this library")
parser.add_argument("-v", "--version", default=version,
help="set version of Eigen to download and build (default: %s)" % version)
# known checksums for different LATTE versions. used to validate the download.
checksums = { \
'1.1.0' : '533635721ee222d0ed2925a18fb5b294', \
'1.2.0' : '68bf0db879da5e068a71281020239ae7', \
'1.2.1' : '85ac414fdada2d04619c8f936344df14', \
}
args = parser.parse_args()
# parse args
# print help message and exit, if neither build nor path options are given
if args.build == False and not args.path:
parser.print_help()
sys.exit(help)
args = sys.argv[1:]
nargs = len(args)
if nargs == 0: error(help=help)
homepath = fullpath(".")
homepath = "."
buildflag = args.build
pathflag = args.path != None
version = args.version
suffixflag = args.machine != None
suffix = args.machine
buildflag = False
pathflag = False
suffixflag = False
linkflag = True
iarg = 0
while iarg < nargs:
if args[iarg] == "-p":
if iarg+2 > nargs: error(help=help)
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(help=help)
suffix = args[iarg+1]
suffixflag = True
iarg += 2
elif args[iarg] == "-v":
if iarg+2 > nargs: error(help=help)
version = args[iarg+1]
iarg += 2
else: error(help=help)
if (pathflag):
lattedir = args.path
if not os.path.isdir(lattedir): sys.exit("LATTE path %s does not exist" % lattedir)
lattedir = fullpath(lattedir)
homedir = "LATTE-%s" % version
if (buildflag and pathflag):
error("Cannot use -b and -p flag at the same time")
if buildflag:
url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version
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:
@ -101,7 +90,7 @@ if buildflag:
# 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")
sys.exit("Checksum for LATTE library does not match")
print("Unpacking LATTE ...")
if os.path.exists(lattedir):
@ -119,30 +108,27 @@ if buildflag:
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print(txt.decode('UTF-8'))
except subprocess.CalledProcessError as e:
print("Make failed with:\n %s" % e.output.decode('UTF-8'))
sys.exit(1)
sys.exit("Make failed with:\n %s" % e.output.decode('UTF-8'))
# create 3 links in lib/latte to LATTE dirs
# do this -b or -p is set
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")
if os.path.isfile("filelink.o") or os.path.islink("filelink.o"):
os.remove("filelink.o")
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)
cmd = 'ln -s "%s/src/latte_c_bind.o" filelink.o' % lattedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
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")
if os.path.isfile("filelink.o") or os.path.islink("filelink.o"):
os.remove("filelink.o")
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)
cmd = 'ln -s "%s/src/latte_c_bind.o" filelink.o' % lattedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# copy Makefile.lammps.suffix to Makefile.lammps
if suffixflag:
if suffixflag or not os.path.exists("Makefile.lammps"):
print("Creating Makefile.lammps")
if os.path.exists("Makefile.lammps.%s" % suffix):
cmd = 'cp Makefile.lammps.%s Makefile.lammps' % suffix