Commit f8a8704e authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

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

parent 1ae112e5
Loading
Loading
Loading
Loading
+18 −20
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir

from __future__ import print_function
import sys,os,re,subprocess,shutil
import sys,os,re,subprocess,shutil,tarfile
sys.path.append('..')
from install_helpers import get_cpus,fullpath,geturl,checkmd5sum
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.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",
                    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'],
                    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)
                    help="set version of LATTE to download and build (default: %s)" % version)

args = parser.parse_args()

@@ -79,7 +79,7 @@ homedir = "LATTE-%s" % version
if buildflag:
  url = "https://github.com/lanl/LATTE/archive/v%s.tar.gz" % version
  lattepath = fullpath(homepath)
  lattedir = "%s/%s" % (lattepath,homedir)
  lattedir = os.path.join(lattepath,homedir)

# download and unpack LATTE tarball

@@ -95,13 +95,14 @@ if buildflag:
  print("Unpacking LATTE ...")
  if os.path.exists(lattedir):
    shutil.rmtree(lattedir)
  cmd = 'cd "%s"; tar zxvf LATTE.tar.gz' % lattepath
  subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  os.remove("%s/LATTE.tar.gz" % lattepath)
  if tarfile.is_tarfile('LATTE.tar.gz'):
    tgz = tarfile.open('LATTE.tar.gz')
    tgz.extractall()
    os.remove('LATTE.tar.gz')
  else:
    sys.exit("File LATTE.tar.gz is not a supported archive")

  # build LATTE

if buildflag:
  print("Building LATTE ...")
  cmd = 'cd "%s"; make' % lattedir
  try:
@@ -119,17 +120,14 @@ 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)
os.symlink(os.path.join(lattedir,'src'),'includelink')
os.symlink(lattedir,'liblink')
os.symlink(os.path.join(lattedir,'src','latte_c_bind.o'),'filelink.o')

# copy Makefile.lammps.suffix to Makefile.lammps

if suffixflag or not os.path.exists("Makefile.lammps"):
  if suffix == None: suffix = 'gfortran'
  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)
    shutil.copyfile("Makefile.lammps.%s" % suffix, 'Makefile.lammps')
+14 −11
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir

from __future__ import print_function
import sys,os,re,glob,subprocess,shutil
import sys,os,re,glob,subprocess,shutil,tarfile
sys.path.append('..')
from install_helpers import fullpath,geturl,checkmd5sum
from argparse import ArgumentParser
@@ -57,7 +57,7 @@ if args.build == False and not args.path:
  sys.exit(help)

homepath = fullpath(".")
eigenpath = "%s/eigen3" % homepath
eigenpath = os.path.join(homepath,"eigen3")

buildflag = args.build
pathflag = args.path != None
@@ -73,29 +73,33 @@ if pathflag:

if buildflag:
  print("Downloading Eigen ...")
  eigentar = os.path.join(homepath,tarball)
  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.
  if version in checksums:
    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")


  print("Cleaning up old folders ...")
  edir = glob.glob("%s/eigen-eigen-*" % homepath)
  edir = glob.glob(os.path.join(homepath,"eigen-eigen-*"))
  edir.append(eigenpath)
  for one in edir:
    if os.path.isdir(one):
      shutil.rmtree(one)

  print("Unpacking Eigen tarball ...")
  cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball)
  subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  edir = glob.glob("%s/eigen-eigen-*" % homepath)
  if tarfile.is_tarfile(eigentar):
    tgz = tarfile.open(eigentar)
    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.remove(tarball)

# 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"):
  os.remove("includelink")
linkdir = eigenpath
cmd = 'ln -s "%s" includelink' % linkdir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.symlink(linkdir,'includelink')
+18 −17
Original line number Diff line number Diff line
@@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir

from __future__ import print_function
import sys,os,re,subprocess,shutil
import sys,os,re,subprocess,shutil,tarfile
sys.path.append('..')
from install_helpers import get_cpus,fullpath,geturl,checkmd5sum
from argparse import ArgumentParser
@@ -61,34 +61,37 @@ pathflag = args.path != None
voropath = args.path

homepath = fullpath(".")
homedir = "%s/%s" % (homepath,version)
homedir = os.path.join(homepath,version)

if pathflag:
    if not os.path.isdir(voropath):
      sys.exit("Voro++ path %s does not exist" % voropath)
    homedir = voropath
    homedir = fullpath(voropath)

# download and unpack Voro++ tarball

if buildflag:
  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.
  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")

  print("Unpacking Voro++ tarball ...")
  if os.path.exists("%s/%s" % (homepath,version)):
    shutil.rmtree("%s/%s" % (homepath,version))
  cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version)
  subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  os.remove("%s/%s.tar.gz" % (homepath,version))
  srcpath = os.path.join(homepath,version)
  if os.path.exists(srcpath): shutil.rmtree(srcpath)
  if tarfile.is_tarfile(vorotar):
    tgz = tarfile.open(vorotar)
    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.exists(homedir):
      shutil.rmtree(homedir)
    os.rename("%s/%s" % (homepath,version),homedir)
    if os.path.exists(homedir): shutil.rmtree(homedir)
    os.rename(srcpath,homedir)

# build Voro++

@@ -109,7 +112,5 @@ 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")
cmd = 'ln -s "%s/src" includelink' % homedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'ln -s "%s/src" liblink' % homedir
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.symlink(os.path.join(homedir,'src'),'includelink')
os.symlink(os.path.join(homedir,'src'),'liblink')