fix gcmc updates from Aidan, trimming of output for replica commands
This commit is contained in:
116
lib/voronoi/Install.py
Normal file
116
lib/voronoi/Install.py
Normal file
@ -0,0 +1,116 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
# install.py tool to download, unpack, build, and link to the Voro++ library
|
||||
# used to automate the steps described in the README file in this dir
|
||||
|
||||
import sys,os,re,urllib,commands
|
||||
|
||||
# help message
|
||||
|
||||
help = """
|
||||
Syntax: install.py -v version -g gdir [gname] -b bdir -l ldir
|
||||
specify one or more options, order does not matter
|
||||
gdir,bdir,ldir can be paths relative to lib/latte, full paths, or contain ~
|
||||
-v = version of Voro++ to download and build
|
||||
default = voro++-0.4.6 (current as of Jan 2015)
|
||||
-g = grab (download) from math.lbl.gov/voro++ website
|
||||
unpack tarfile in gdir to produce version dir (e.g. voro++-0.4.6)
|
||||
if optional gname specified, rename version dir to gname within gdir
|
||||
-b = build Voro++, bdir = Voro++ home directory
|
||||
note that bdir must include the version suffix unless renamed
|
||||
-l = create 2 softlinks (includelink,liblink)
|
||||
in lib/voronoi to src dir of ldir = Voro++ home directory
|
||||
note that ldir must include the version suffix unless renamed
|
||||
"""
|
||||
|
||||
# settings
|
||||
|
||||
version = "voro++-0.4.6"
|
||||
url = "http://math.lbl.gov/voro++/download/dir/%s.tar.gz" % version
|
||||
|
||||
# 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))
|
||||
|
||||
# parse args
|
||||
|
||||
args = sys.argv[1:]
|
||||
nargs = len(args)
|
||||
if nargs == 0: error()
|
||||
|
||||
grabflag = 0
|
||||
buildflag = 0
|
||||
linkflag = 0
|
||||
|
||||
iarg = 0
|
||||
while iarg < nargs:
|
||||
if args[iarg] == "-v":
|
||||
if iarg+2 > nargs: error()
|
||||
version = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-g":
|
||||
if iarg+2 > nargs: error()
|
||||
grabflag = 1
|
||||
grabdir = args[iarg+1]
|
||||
grabname = None
|
||||
if iarg+2 < nargs and args[iarg+2][0] != '-':
|
||||
grabname = args[iarg+2]
|
||||
iarg += 1
|
||||
iarg += 2
|
||||
elif args[iarg] == "-b":
|
||||
if iarg+2 > nargs: error()
|
||||
buildflag = 1
|
||||
builddir = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-l":
|
||||
if iarg+2 > nargs: error()
|
||||
linkflag = 1
|
||||
linkdir = args[iarg+1]
|
||||
iarg += 2
|
||||
else: error()
|
||||
|
||||
# download and unpack Voro++ tarball
|
||||
|
||||
if grabflag:
|
||||
print "Downloading Voro++ ..."
|
||||
grabdir = fullpath(grabdir)
|
||||
if not os.path.isdir(grabdir): error("Grab directory does not exist")
|
||||
urllib.urlretrieve(url,"%s/%s.tar.gz" % (grabdir,version))
|
||||
|
||||
print "Unpacking Voro++ tarball ..."
|
||||
tardir = "%s/%s" % (grabdir,version)
|
||||
if os.path.exists(tardir): commands.getoutput("rm -rf %s" % tardir)
|
||||
cmd = "cd %s; tar zxvf %s.tar.gz" % (grabdir,version)
|
||||
txt = commands.getoutput(cmd)
|
||||
print tardir,grabdir,grabname
|
||||
if grabname: os.rename(tardir,"%s/%s" % (grabdir,grabname))
|
||||
|
||||
# build Voro++
|
||||
|
||||
if buildflag:
|
||||
print "Building Voro++ ..."
|
||||
cmd = "cd %s; make" % builddir
|
||||
txt = commands.getoutput(cmd)
|
||||
print txt
|
||||
|
||||
# create 2 links in lib/voronoi to Voro++ src dir
|
||||
|
||||
if linkflag:
|
||||
print "Creating links to Voro++ include and lib 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")
|
||||
cmd = "ln -s %s/src includelink" % linkdir
|
||||
commands.getoutput(cmd)
|
||||
cmd = "ln -s %s/src liblink" % linkdir
|
||||
commands.getoutput(cmd)
|
||||
@ -9,8 +9,8 @@ Laboratory.
|
||||
-----------------
|
||||
|
||||
You must perform the following steps yourself, or you can use the
|
||||
install.py Python script to automate any or all steps of the process.
|
||||
Type "python install.py" for instructions.
|
||||
Install.py Python script to automate any or all steps of the process.
|
||||
Type "python Install.py" for instructions.
|
||||
|
||||
1. Download Voro++ at http://math.lbl.gov/voro++/download
|
||||
either as a tarball or via SVN, and unpack the
|
||||
|
||||
@ -1,163 +0,0 @@
|
||||
#!usr/local/python
|
||||
|
||||
# install.py tool to download, unpack, build, and link to the Voro++ library
|
||||
# used to automate the steps described in the README file in this dir
|
||||
|
||||
import sys,os,re,urllib,commands
|
||||
|
||||
help = """
|
||||
Syntax: install.py -d dir -v version -g -b -i installdir -l incdir libdir
|
||||
specify one or more options, order does not matter
|
||||
-d = dir to download tarball to, unpack tarball in, perform build in
|
||||
dir will be created if it doesn't exist (only last level)
|
||||
default = this dir
|
||||
-v = version of Voro++ to download and work with
|
||||
default = voro++-0.4.6 (current as of Jan 2015)
|
||||
-g = download (grab) tarball from
|
||||
http://math.lbl.gov/voro++/download/dir/version
|
||||
-b = build Voro++ by invoking "make" in its home dir
|
||||
no default
|
||||
-i = install Voro++ by invoking "make install" in its home dir
|
||||
installdir arg is optional:
|
||||
if not specified, installs at PREFIX defined in config.mk file
|
||||
if specified, will overwrite PREFIX and install there
|
||||
if PREFIX starts with /usr, will invoke "sudo make install"
|
||||
-l = create two links to incdir and libdir
|
||||
incdir and libdir are optional (specify neither or both):
|
||||
if specified, includelink and liblink are to those two dirs
|
||||
these are dirs where Voro++ include files and lib file are
|
||||
if not specified and no install, links are to Voro++ src dir
|
||||
if not specified and install performed,
|
||||
links are to include and lib dirs under PREFIX
|
||||
"""
|
||||
|
||||
def error():
|
||||
print help
|
||||
sys.exit()
|
||||
|
||||
# parse args
|
||||
|
||||
args = sys.argv
|
||||
|
||||
if len(args) == 1: error()
|
||||
|
||||
dir = "."
|
||||
version = "voro++-0.4.6"
|
||||
grabflag = 0
|
||||
buildflag = 0
|
||||
installflag = 0
|
||||
linkflag = 0
|
||||
|
||||
iarg = 1
|
||||
while iarg < len(args):
|
||||
if args[iarg] == "-d":
|
||||
if iarg+2 > len(args): error()
|
||||
dir = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-v":
|
||||
if iarg+2 > len(args): error()
|
||||
version = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-g":
|
||||
grabflag = 1
|
||||
iarg += 1
|
||||
elif args[iarg] == "-b":
|
||||
buildflag = 1
|
||||
iarg += 1
|
||||
elif args[iarg] == "-i":
|
||||
installflag = 1
|
||||
if iarg+1 == len(args) or args[iarg+1][0] == '-':
|
||||
installdir = ""
|
||||
iarg += 1
|
||||
else:
|
||||
if iarg+2 > len(args): error()
|
||||
installdir = args[iarg+1]
|
||||
iarg += 2
|
||||
elif args[iarg] == "-l":
|
||||
linkflag = 1
|
||||
if iarg+1 == len(args) or args[iarg+1][0] == '-' or \
|
||||
iarg+2 == len(args) or args[iarg+2][0] == '-':
|
||||
includedir = libdir = ""
|
||||
iarg += 1
|
||||
else:
|
||||
if iarg+3 > len(args): error()
|
||||
includedir = args[iarg+1]
|
||||
libdir = args[iarg+2]
|
||||
iarg += 3
|
||||
else: error()
|
||||
|
||||
dir = os.path.abspath(dir)
|
||||
url = "http://math.lbl.gov/voro++/download/dir/%s.tar.gz" % version
|
||||
|
||||
# create dir if does not exist
|
||||
|
||||
if not os.path.isdir(dir):
|
||||
if os.path.isfile(dir):
|
||||
print "ERROR: Dir already exists as file"
|
||||
sys.exit()
|
||||
os.mkdir(dir)
|
||||
if not os.path.isdir(dir):
|
||||
print "ERROR: Unable to create dir"
|
||||
sys.exit()
|
||||
|
||||
# download and unpack tarball
|
||||
|
||||
if grabflag:
|
||||
print "Downloading Voro++ tarball ..."
|
||||
urllib.urlretrieve(url,"%s/%s.tar.gz" % (dir,version))
|
||||
print "Unpacking Voro++ tarball ..."
|
||||
cmd = "cd %s; tar zxvf %s.tar.gz" % (dir,version)
|
||||
txt = commands.getoutput(cmd)
|
||||
|
||||
# build Voro++ in its dir
|
||||
|
||||
if buildflag:
|
||||
print "Building Voro++ ..."
|
||||
cmd = "cd %s/%s; make" % (dir,version)
|
||||
txt = commands.getoutput(cmd)
|
||||
print txt
|
||||
|
||||
# install Voro++
|
||||
# if installdir set, overwrite PREFIX var in its config.mk file
|
||||
# if PREFIX var starts with /usr, invoke sudo make install, else make install
|
||||
|
||||
if installflag:
|
||||
print "Installing Voro++ ..."
|
||||
if installdir:
|
||||
txt = open("%s/%s/config.mk" % (dir,version),'r').read()
|
||||
txt = re.sub("PREFIX=.*?\n","PREFIX=%s\n" % installdir,txt)
|
||||
open("%s/%s/config.mk" % (dir,version),'w').write(txt)
|
||||
print "TXT:",txt
|
||||
txt = open("%s/%s/config.mk" % (dir,version),'r').read()
|
||||
var = re.findall("PREFIX=.*?\n",txt)
|
||||
prefix = var[0].split('=')[1].strip()
|
||||
if prefix.startswith("/usr"):
|
||||
cmd = "cd %s/%s; sudo make install" % (dir,version)
|
||||
else:
|
||||
cmd = "cd %s/%s; make install" % (dir,version)
|
||||
txt = commands.getoutput(cmd)
|
||||
print txt
|
||||
|
||||
# create links in this dir to Voro++ include and lib files
|
||||
|
||||
if linkflag:
|
||||
print "Creating links to Voro++ include and lib 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 includedir:
|
||||
cmd = "ln -s %s includelink" % includedir
|
||||
txt = commands.getoutput(cmd)
|
||||
cmd = "ln -s %s liblink" % linkdir
|
||||
txt = commands.getoutput(cmd)
|
||||
elif not installflag:
|
||||
cmd = "ln -s %s/%s/src includelink" % (dir,version)
|
||||
txt = commands.getoutput(cmd)
|
||||
cmd = "ln -s %s/%s/src liblink" % (dir,version)
|
||||
txt = commands.getoutput(cmd)
|
||||
else:
|
||||
cmd = "ln -s %s/include includelink" % prefix
|
||||
txt = commands.getoutput(cmd)
|
||||
cmd = "ln -s %s/lib liblink" % prefix
|
||||
txt = commands.getoutput(cmd)
|
||||
Reference in New Issue
Block a user