use os.path.join(), os.symlink(), shutile.copyfile() and tarfile module

This commit is contained in:
Axel Kohlmeyer
2019-01-15 18:07:50 -05:00
parent 1ae112e563
commit f8a8704ef4
3 changed files with 49 additions and 47 deletions

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess,shutil import sys,os,re,subprocess,shutil,tarfile
sys.path.append('..') sys.path.append('..')
from install_helpers import get_cpus,fullpath,geturl,checkmd5sum from install_helpers import get_cpus,fullpath,geturl,checkmd5sum
from argparse import ArgumentParser from argparse import ArgumentParser
@ -46,13 +46,13 @@ make lib-latte args="-p $HOME/latte" # use existing LATTE installation
pgroup = parser.add_mutually_exclusive_group() pgroup = parser.add_mutually_exclusive_group()
pgroup.add_argument("-b", "--build", action="store_true", pgroup.add_argument("-b", "--build", action="store_true",
help="download and build the Eigen3 library") help="download and build the LATTE library")
pgroup.add_argument("-p", "--path", pgroup.add_argument("-p", "--path",
help="specify folder of existing Eigen installation") help="specify folder of existing LATTE installation")
parser.add_argument("-m", "--machine", choices=['gfortran','ifort','linalg','serial','mpi'], 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") help="suffix of a Makefile.lammps.* file used for linking LAMMPS with this library")
parser.add_argument("-v", "--version", default=version, parser.add_argument("-v", "--version", default=version,
help="set version of Eigen to download and build (default: %s)" % version) help="set version of LATTE to download and build (default: %s)" % version)
args = parser.parse_args() args = parser.parse_args()
@ -79,7 +79,7 @@ homedir = "LATTE-%s" % version
if buildflag: if buildflag:
url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version
lattepath = fullpath(homepath) lattepath = fullpath(homepath)
lattedir = "%s/%s" % (lattepath,homedir) lattedir = os.path.join(lattepath,homedir)
# download and unpack LATTE tarball # download and unpack LATTE tarball
@ -95,13 +95,14 @@ if buildflag:
print("Unpacking LATTE ...") print("Unpacking LATTE ...")
if os.path.exists(lattedir): if os.path.exists(lattedir):
shutil.rmtree(lattedir) shutil.rmtree(lattedir)
cmd = 'cd "%s"; tar zxvf LATTE.tar.gz' % lattepath if tarfile.is_tarfile('LATTE.tar.gz'):
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) tgz = tarfile.open('LATTE.tar.gz')
os.remove("%s/LATTE.tar.gz" % lattepath) tgz.extractall()
os.remove('LATTE.tar.gz')
else:
sys.exit("File LATTE.tar.gz is not a supported archive")
# build LATTE # build LATTE
if buildflag:
print("Building LATTE ...") print("Building LATTE ...")
cmd = 'cd "%s"; make' % lattedir cmd = 'cd "%s"; make' % lattedir
try: try:
@ -119,17 +120,14 @@ if os.path.isfile("liblink") or os.path.islink("liblink"):
os.remove("liblink") os.remove("liblink")
if os.path.isfile("filelink.o") or os.path.islink("filelink.o"): if os.path.isfile("filelink.o") or os.path.islink("filelink.o"):
os.remove("filelink.o") os.remove("filelink.o")
cmd = 'ln -s "%s/src" includelink' % lattedir os.symlink(os.path.join(lattedir,'src'),'includelink')
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.symlink(lattedir,'liblink')
cmd = 'ln -s "%s" liblink' % lattedir os.symlink(os.path.join(lattedir,'src','latte_c_bind.o'),'filelink.o')
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 # copy Makefile.lammps.suffix to Makefile.lammps
if suffixflag or not os.path.exists("Makefile.lammps"): if suffixflag or not os.path.exists("Makefile.lammps"):
if suffix == None: suffix = 'gfortran'
print("Creating Makefile.lammps") print("Creating Makefile.lammps")
if os.path.exists("Makefile.lammps.%s" % suffix): if os.path.exists("Makefile.lammps.%s" % suffix):
cmd = 'cp Makefile.lammps.%s Makefile.lammps' % suffix shutil.copyfile("Makefile.lammps.%s" % suffix, 'Makefile.lammps')
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,glob,subprocess,shutil import sys,os,re,glob,subprocess,shutil,tarfile
sys.path.append('..') sys.path.append('..')
from install_helpers import fullpath,geturl,checkmd5sum from install_helpers import fullpath,geturl,checkmd5sum
from argparse import ArgumentParser from argparse import ArgumentParser
@ -57,7 +57,7 @@ if args.build == False and not args.path:
sys.exit(help) sys.exit(help)
homepath = fullpath(".") homepath = fullpath(".")
eigenpath = "%s/eigen3" % homepath eigenpath = os.path.join(homepath,"eigen3")
buildflag = args.build buildflag = args.build
pathflag = args.path != None pathflag = args.path != None
@ -73,29 +73,33 @@ if pathflag:
if buildflag: if buildflag:
print("Downloading Eigen ...") print("Downloading Eigen ...")
eigentar = os.path.join(homepath,tarball)
url = "http://bitbucket.org/eigen/eigen/get/%s.tar.gz" % version url = "http://bitbucket.org/eigen/eigen/get/%s.tar.gz" % version
geturl(url,"%s/%s" % (homepath,tarball)) geturl(url,eigentar)
# verify downloaded archive integrity via md5 checksum, if known. # verify downloaded archive integrity via md5 checksum, if known.
if version in checksums: if version in checksums:
print("checking version %s\n" % version) print("checking version %s\n" % version)
if not checkmd5sum(checksums[version],'%s/%s' % (homepath,tarball)): if not checkmd5sum(checksums[version],eigentar):
sys.exit("Checksum for Eigen library does not match") sys.exit("Checksum for Eigen library does not match")
print("Cleaning up old folders ...") print("Cleaning up old folders ...")
edir = glob.glob("%s/eigen-eigen-*" % homepath) edir = glob.glob(os.path.join(homepath,"eigen-eigen-*"))
edir.append(eigenpath) edir.append(eigenpath)
for one in edir: for one in edir:
if os.path.isdir(one): if os.path.isdir(one):
shutil.rmtree(one) shutil.rmtree(one)
print("Unpacking Eigen tarball ...") print("Unpacking Eigen tarball ...")
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball) if tarfile.is_tarfile(eigentar):
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) tgz = tarfile.open(eigentar)
edir = glob.glob("%s/eigen-eigen-*" % homepath) tgz.extractall(path=homepath)
os.remove(eigentar)
else:
sys.exit("File %s is not a supported archive" % eigentar)
edir = glob.glob(os.path.join(homepath,"eigen-eigen-*"))
os.rename(edir[0],eigenpath) os.rename(edir[0],eigenpath)
os.remove(tarball)
# create link in lib/smd to Eigen src dir # create link in lib/smd to Eigen src dir
@ -103,5 +107,4 @@ print("Creating link to Eigen include folder")
if os.path.isfile("includelink") or os.path.islink("includelink"): if os.path.isfile("includelink") or os.path.islink("includelink"):
os.remove("includelink") os.remove("includelink")
linkdir = eigenpath linkdir = eigenpath
cmd = 'ln -s "%s" includelink' % linkdir os.symlink(linkdir,'includelink')
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess,shutil import sys,os,re,subprocess,shutil,tarfile
sys.path.append('..') sys.path.append('..')
from install_helpers import get_cpus,fullpath,geturl,checkmd5sum from install_helpers import get_cpus,fullpath,geturl,checkmd5sum
from argparse import ArgumentParser from argparse import ArgumentParser
@ -61,34 +61,37 @@ pathflag = args.path != None
voropath = args.path voropath = args.path
homepath = fullpath(".") homepath = fullpath(".")
homedir = "%s/%s" % (homepath,version) homedir = os.path.join(homepath,version)
if pathflag: if pathflag:
if not os.path.isdir(voropath): if not os.path.isdir(voropath):
sys.exit("Voro++ path %s does not exist" % voropath) sys.exit("Voro++ path %s does not exist" % voropath)
homedir = voropath homedir = fullpath(voropath)
# download and unpack Voro++ tarball # download and unpack Voro++ tarball
if buildflag: if buildflag:
print("Downloading Voro++ ...") print("Downloading Voro++ ...")
geturl(url,"%s/%s.tar.gz" % (homepath,version)) vorotar = os.path.join(homepath,version) + '.tar.gz'
geturl(url,vorotar)
# verify downloaded archive integrity via md5 checksum, if known. # verify downloaded archive integrity via md5 checksum, if known.
if version in checksums: if version in checksums:
if not checkmd5sum(checksums[version],'%s/%s.tar.gz' % (homepath,version)): if not checkmd5sum(checksums[version],vorotar):
sys.exit("Checksum for Voro++ library does not match") sys.exit("Checksum for Voro++ library does not match")
print("Unpacking Voro++ tarball ...") print("Unpacking Voro++ tarball ...")
if os.path.exists("%s/%s" % (homepath,version)): srcpath = os.path.join(homepath,version)
shutil.rmtree("%s/%s" % (homepath,version)) if os.path.exists(srcpath): shutil.rmtree(srcpath)
cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version) if tarfile.is_tarfile(vorotar):
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) tgz = tarfile.open(vorotar)
os.remove("%s/%s.tar.gz" % (homepath,version)) tgz.extractall(path=homepath)
os.remove(vorotar)
else:
sys.exit("File %s is not a supported archive" % vorotar)
if os.path.basename(homedir) != version: if os.path.basename(homedir) != version:
if os.path.exists(homedir): if os.path.exists(homedir): shutil.rmtree(homedir)
shutil.rmtree(homedir) os.rename(srcpath,homedir)
os.rename("%s/%s" % (homepath,version),homedir)
# build Voro++ # build Voro++
@ -109,7 +112,5 @@ if os.path.isfile("includelink") or os.path.islink("includelink"):
os.remove("includelink") os.remove("includelink")
if os.path.isfile("liblink") or os.path.islink("liblink"): if os.path.isfile("liblink") or os.path.islink("liblink"):
os.remove("liblink") os.remove("liblink")
cmd = 'ln -s "%s/src" includelink' % homedir os.symlink(os.path.join(homedir,'src'),'includelink')
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.symlink(os.path.join(homedir,'src'),'liblink')
cmd = 'ln -s "%s/src" liblink' % homedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)