consolidate shared code from various Install.py files into install_helpers.py
This commit is contained in:
@ -5,6 +5,8 @@
|
||||
|
||||
from __future__ import print_function
|
||||
import sys,os,re,subprocess,shutil
|
||||
sys.path.append('..')
|
||||
from install_helpers import error,get_cpus,fullpath,which,get_cpus,geturl
|
||||
|
||||
# help message
|
||||
|
||||
@ -35,64 +37,11 @@ url = "https://github.com/uchicago-voth/MSCG-release/archive/%s.tar.gz" % mscgve
|
||||
tarfile = "MS-CG-%s.tar.gz" % mscgver
|
||||
tardir = "MSCG-release-%s" % mscgver
|
||||
|
||||
# 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
|
||||
|
||||
# parse args
|
||||
|
||||
args = sys.argv[1:]
|
||||
nargs = len(args)
|
||||
if nargs == 0: error()
|
||||
if nargs == 0: error(help=help)
|
||||
|
||||
homepath = "."
|
||||
homedir = tardir
|
||||
@ -105,18 +54,18 @@ msuffix = "g++_simple"
|
||||
iarg = 0
|
||||
while iarg < nargs:
|
||||
if args[iarg] == "-p":
|
||||
if iarg+2 > nargs: error()
|
||||
if iarg+2 > nargs: error(help=help)
|
||||
mscgpath = fullpath(args[iarg+1])
|
||||
pathflag = True
|
||||
iarg += 2
|
||||
elif args[iarg] == "-m":
|
||||
if iarg+2 > nargs: error()
|
||||
if iarg+2 > nargs: error(help=help)
|
||||
msuffix = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-b":
|
||||
buildflag = True
|
||||
iarg += 1
|
||||
else: error()
|
||||
else: error(help=help)
|
||||
|
||||
homepath = fullpath(homepath)
|
||||
homedir = "%s/%s" % (homepath,homedir)
|
||||
@ -160,8 +109,13 @@ if buildflag:
|
||||
(homedir,msuffix,msuffix)
|
||||
else:
|
||||
error("Cannot find Makefile.%s" % msuffix)
|
||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||
print(txt.decode('UTF-8'))
|
||||
try:
|
||||
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)
|
||||
|
||||
if not os.path.exists("Makefile.lammps"):
|
||||
print("Creating Makefile.lammps")
|
||||
if os.path.exists("Makefile.lammps.%s" % msuffix):
|
||||
|
||||
Reference in New Issue
Block a user