some cleanups and small bugfixes to conform better with python conventions
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# Install.py tool to download, unpack, build, and link to the MS-CG library
|
||||
# used to automate the steps described in the README file in this dir
|
||||
"""
|
||||
Install.py tool to download, unpack, build, and link to the MS-CG library
|
||||
used to automate the steps described in the README file in this dir
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
import sys,os,re,subprocess,shutil,tarfile
|
||||
sys.path.append('..')
|
||||
from install_helpers import get_cpus,fullpath,get_cpus,geturl
|
||||
|
||||
import sys, os, subprocess, shutil, tarfile
|
||||
from argparse import ArgumentParser
|
||||
|
||||
sys.path.append('..')
|
||||
from install_helpers import fullpath, geturl
|
||||
|
||||
parser = ArgumentParser(prog='Install.py',
|
||||
description="LAMMPS library build wrapper script")
|
||||
|
||||
@ -20,7 +22,7 @@ machine = "g++_simple"
|
||||
|
||||
# help message
|
||||
|
||||
help = """
|
||||
HELP = """
|
||||
Syntax from src dir: make lib-mscg args="-p [path] -m [suffix] -v [version]"
|
||||
or: make lib-mscg args="-b -m [suffix]"
|
||||
Syntax from lib dir: python Install.py -p [path] -m [suffix] -v [version]
|
||||
@ -47,19 +49,19 @@ pgroup.add_argument("-p", "--path",
|
||||
help="specify folder of existing MSCG installation")
|
||||
parser.add_argument("-v", "--version", default=version, choices=checksums.keys(),
|
||||
help="set version of MSCG to download and build (default: %s)" % version)
|
||||
parser.add_argument("-m", "--machine", default=machine, choices=['mpi','serial','g++_simple','intel_simple','lapack', 'mac'],
|
||||
parser.add_argument("-m", "--machine", default=machine, choices=['mpi', 'serial', 'g++_simple', 'intel_simple', 'lapack', 'mac'],
|
||||
help="set machine suffix specifies which src/Make/Makefile.suffix to use. (default: %s)" % machine)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# print help message and exit, if neither build nor path options are given
|
||||
if args.build == False and not args.path:
|
||||
if not args.build and not args.path:
|
||||
parser.print_help()
|
||||
sys.exit(help)
|
||||
sys.exit(HELP)
|
||||
|
||||
buildflag = args.build
|
||||
pathflag = args.path != None
|
||||
mscgpath= args.path
|
||||
pathflag = args.path is not None
|
||||
mscgpath = args.path
|
||||
msuffix = args.machine
|
||||
mscgver = args.version
|
||||
|
||||
@ -70,7 +72,7 @@ tarname = "MS-CG-%s.tar.gz" % mscgver
|
||||
tardir = "MSCG-release-%s" % mscgver
|
||||
|
||||
homepath = fullpath('.')
|
||||
homedir = os.path.join(homepath,tardir)
|
||||
homedir = os.path.join(homepath, tardir)
|
||||
|
||||
if pathflag:
|
||||
if not os.path.isdir(mscgpath):
|
||||
@ -81,41 +83,41 @@ if pathflag:
|
||||
|
||||
if buildflag:
|
||||
print("Downloading MS-CG ...")
|
||||
tarname = os.path.join(homepath,tarname)
|
||||
geturl(url,tarname)
|
||||
tarname = os.path.join(homepath, tarname)
|
||||
geturl(url, tarname)
|
||||
|
||||
print("Unpacking MS-CG tarfile ...")
|
||||
|
||||
if os.path.exists(os.path.join(homepath,tardir)):
|
||||
shutil.rmtree(os.path.join(homepath,tardir))
|
||||
|
||||
if os.path.exists(os.path.join(homepath, tardir)):
|
||||
shutil.rmtree(os.path.join(homepath, tardir))
|
||||
|
||||
if tarfile.is_tarfile(tarname):
|
||||
tgz = tarfile.open(tarname)
|
||||
tgz.extractall(path=homepath)
|
||||
os.remove(tarname)
|
||||
else:
|
||||
sys.exit("File %s is not a supported archive",tarname)
|
||||
sys.exit("File %s is not a supported archive", tarname)
|
||||
|
||||
if os.path.basename(homedir) != tardir:
|
||||
if os.path.exists(homedir):
|
||||
shutil.rmtree(homedir)
|
||||
os.rename(os.path.join(homepath,tardir),homedir)
|
||||
os.rename(os.path.join(homepath, tardir), homedir)
|
||||
|
||||
# build MS-CG
|
||||
|
||||
if buildflag:
|
||||
print("Building MS-CG ...")
|
||||
mkf="Makefile.%s" % msuffix
|
||||
mkp=os.path.join(homedir,'src','Make',mkf)
|
||||
mkf = "Makefile.%s" % msuffix
|
||||
mkp = os.path.join(homedir, 'src', 'Make', mkf)
|
||||
if os.path.exists(mkp):
|
||||
shutil.copyfile(mkp,os.path.join(homedir,'src',mkf))
|
||||
shutil.copyfile(mkp, os.path.join(homedir, 'src', mkf))
|
||||
elif os.path.exists("Makefile.%s" % msuffix):
|
||||
shutil.copyfile("Makefile.%s" % msuffix,os.path.join(homedir,'src',mkf))
|
||||
shutil.copyfile("Makefile.%s" % msuffix, os.path.join(homedir, 'src', mkf))
|
||||
else:
|
||||
sys.exit("Cannot find Makefile.%s" % msuffix)
|
||||
try:
|
||||
cmd = 'make -C %s -f Makefile.%s' % (os.path.join(homedir,'src'),msuffix)
|
||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||
cmd = 'make -C %s -f Makefile.%s' % (os.path.join(homedir, 'src'), msuffix)
|
||||
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'))
|
||||
@ -124,9 +126,9 @@ if buildflag:
|
||||
if not os.path.exists("Makefile.lammps"):
|
||||
print("Creating Makefile.lammps")
|
||||
if os.path.exists("Makefile.lammps.%s" % msuffix):
|
||||
shutil.copyfile('Makefile.lammps.%s' % msuffix,'Makefile.lammps')
|
||||
shutil.copyfile('Makefile.lammps.%s' % msuffix, 'Makefile.lammps')
|
||||
else:
|
||||
shutil.copyfile('Makefile.lammps.default','Makefile.lammps')
|
||||
shutil.copyfile('Makefile.lammps.default', 'Makefile.lammps')
|
||||
else: print("Makefile.lammps exists. Please check its settings")
|
||||
|
||||
# create 2 links in lib/mscg to MS-CG src dir
|
||||
@ -136,5 +138,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")
|
||||
os.symlink(os.path.join(homedir,'src'),'includelink')
|
||||
os.symlink(os.path.join(homedir,'src'),'liblink')
|
||||
os.symlink(os.path.join(homedir, 'src'), 'includelink')
|
||||
os.symlink(os.path.join(homedir, 'src'), 'liblink')
|
||||
|
||||
Reference in New Issue
Block a user