diff --git a/lib/kim/Install.py b/lib/kim/Install.py index 21ea85985..aa244ee6e 100644 --- a/lib/kim/Install.py +++ b/lib/kim/Install.py @@ -1,301 +1,317 @@ #!/usr/bin/env python # install.py tool to download, compile, and setup the kim-api library # used to automate the steps described in the README file in this dir from __future__ import print_function import sys,os,re,subprocess +# help message + help = """ Syntax from src dir: make lib-kim args="-b -v version -a kim-name" or: make lib-kim args="-b -a everything" or: make lib-kim args="-n -a kim-name" or: make lib-kim args="-p /usr/local/open-kim -a kim-name" Syntax from lib dir: python Install.py -b -v version -a kim-name or: python Install.py -b -a everything or: python Install.py -n -a kim-name or: python Install.py -p /usr/local/open-kim -a kim-name specify one or more options, order does not matter -v = version of KIM API library to use default = kim-api-v1.8.2 (current as of June 2017) -b = download and build base KIM API library with example Models this will delete any previous installation in the current folder -n = do NOT download and build base KIM API library. - Use an existing installation + Use an existing installation -p = specify location of KIM API installation (implies -n) -a = add single KIM model or model driver with kim-name to existing KIM API lib (see example below). If kim-name = everything, then rebuild KIM API library with *all* available OpenKIM Models (make take a long time). -vv = be more verbose about what is happening while the script runs Examples: make lib-kim args="-b" # install KIM API lib with only example models make lib-kim args="-a Glue_Ercolessi_Adams_Al__MO_324507536345_001" # Ditto plus one model make lib-kim args="-b -a everything" # install KIM API lib with all models make lib-kim args="-n -a EAM_Dynamo_Ackland_W__MO_141627196590_002" # only add one model or model driver See the list of KIM model drivers here: https://openkim.org/kim-items/model-drivers/alphabetical See the list of all KIM models here: https://openkim.org/kim-items/models/by-model-drivers See the list of example KIM models included by default here: https://openkim.org/kim-api in the "What is in the KIM API source package?" section """ 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) - elif which('wget') != None: + 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) - else: error("cannot find 'wget' or 'curl' to download source code") - txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) - return txt + 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() thisdir = os.environ['PWD'] version = "kim-api-v1.8.2" buildflag = False everythingflag = False addflag = False verboseflag = False pathflag = False iarg = 0 while iarg < len(args): if args[iarg] == "-v": if iarg+2 > len(args): error() version = args[iarg+1] iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 elif args[iarg] == "-n": buildflag = False iarg += 1 elif args[iarg] == "-p": if iarg+2 > len(args): error() kimdir = fullpath(args[iarg+1]) pathflag = True buildflag = False iarg += 2 elif args[iarg] == "-a": addflag = True if iarg+2 > len(args): error() addmodelname = args[iarg+1] if addmodelname == "everything": buildflag = True everythingflag = True addflag = False iarg += 2 elif args[iarg] == "-vv": verboseflag = True iarg += 1 else: error() thisdir = os.path.abspath(thisdir) url = "https://s3.openkim.org/kim-api/%s.tgz" % version # set KIM API directory if pathflag: if not os.path.isdir(kimdir): print("\nkim-api is not installed at %s" % kimdir) error() # configure LAMMPS to use existing kim-api installation with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile: mkfile.write("KIM_INSTALL_DIR=%s\n\n" % kimdir) mkfile.write(".DUMMY: print_dir\n\n") mkfile.write("print_dir:\n") mkfile.write(" @printf $(KIM_INSTALL_DIR)\n") with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile: cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir) print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir)) else: kimdir = os.path.join(os.path.abspath(thisdir), "installed-" + version) # download KIM tarball, unpack, build KIM if buildflag: # check to see if an installed kim-api already exists and wipe it out. if os.path.isdir(kimdir): print("kim-api is already installed at %s.\nRemoving it for re-install" % kimdir) cmd = 'rm -rf "%s"' % kimdir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # configure LAMMPS to use kim-api to be installed with open("%s/Makefile.KIM_DIR" % thisdir, 'w') as mkfile: mkfile.write("KIM_INSTALL_DIR=%s\n\n" % kimdir) mkfile.write(".DUMMY: print_dir\n\n") mkfile.write("print_dir:\n") mkfile.write(" @printf $(KIM_INSTALL_DIR)\n") with open("%s/Makefile.KIM_Config" % thisdir, 'w') as cfgfile: cfgfile.write("include %s/lib/kim-api/Makefile.KIM_Config" % kimdir) print("Created %s/Makefile.KIM_DIR\n using %s" % (thisdir,kimdir)) # download entire kim-api tarball print("Downloading kim-api tarball ...") geturl(url,"%s/%s.tgz" % (thisdir,version)) print("Unpacking kim-api tarball ...") cmd = 'cd "%s"; rm -rf "%s"; tar -xzvf %s.tgz' % (thisdir,version,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # configure kim-api print("Configuring kim-api ...") cmd = 'cd "%s/%s"; ./configure --prefix="%s"' % (thisdir,version,kimdir) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # build kim-api print("Configuring example Models") cmd = 'cd "%s/%s"; make add-examples' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print (txt.decode("UTF-8")) if everythingflag: print("Configuring all OpenKIM models, this will take a while ...") cmd = 'cd "%s/%s"; make add-OpenKIM' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) print("Building kim-api ...") cmd = 'cd "%s/%s"; make' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) # install kim-api print("Installing kim-api ...") cmd = 'cd "%s/%s"; make install' % (thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) cmd = 'cd "%s/%s"; make install-set-default-to-v1' %(thisdir,version) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) if verboseflag: print(txt.decode("UTF-8")) # remove source files print("Removing kim-api source and build files ...") cmd = 'cd "%s"; rm -rf %s; rm -rf %s.tgz' % (thisdir,version,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) # add a single model (and possibly its driver) to existing KIM installation if addflag: if not os.path.isdir(kimdir): print("\nkim-api is not installed") error() # download single model print("Downloading tarball for %s..." % addmodelname) url = "https://openkim.org/download/%s.tgz" % addmodelname geturl(url,"%s/%s.tgz" % (thisdir,addmodelname)) print("Unpacking item tarball ...") cmd = 'cd "%s"; tar -xzvf %s.tgz' % (thisdir,addmodelname) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print("Building item ...") cmd = 'cd "%s/%s"; make; make install' %(thisdir,addmodelname) try: txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) except subprocess.CalledProcessError as e: # Error: but first, check to see if it needs a driver firstRunOutput = e.output.decode("UTF-8") cmd = 'cd "%s/%s"; make kim-item-type' % (thisdir,addmodelname) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = txt.decode("UTF-8") if txt == "ParameterizedModel": # Get and install driver cmd = 'cd "%s/%s"; make model-driver-name' % (thisdir,addmodelname) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) adddrivername = txt.decode("UTF-8").strip() print("First installing model driver: %s..." % adddrivername) cmd = 'cd "%s"; python Install.py -n -a %s' % (thisdir,adddrivername) try: txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) except subprocess.CalledProcessError as e: print(e.output) sys.exit() if verboseflag: print(txt.decode("UTF-8")) # now install the model that needed the driver print("Now installing model : %s" % addmodelname) cmd = 'cd "%s"; python Install.py -n -a %s' % (thisdir,addmodelname) try: txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) except subprocess.CalledProcessError as e: print(e.output) sys.exit() print(txt.decode("UTF-8")) sys.exit() else: print(firstRunOutput) print("Error, unable to build and install OpenKIM item: %s" \ % addmodelname) sys.exit() # success the first time if verboseflag: print(txt.decode("UTF-8")) print("Removing kim item source and build files ...") cmd = 'cd "%s"; rm -rf %s; rm -rf %s.tgz' %(thisdir,addmodelname,addmodelname) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) diff --git a/lib/mscg/Install.py b/lib/mscg/Install.py index 154f5aa52..76c986ef6 100644 --- a/lib/mscg/Install.py +++ b/lib/mscg/Install.py @@ -1,172 +1,186 @@ #!/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 from __future__ import print_function import sys,os,re,subprocess # help message help = """ Syntax from src dir: make lib-mscg args="-p [path] -m [suffix]" or: make lib-mscg args="-b -m [suffix]" Syntax from lib dir: python Install.py -p [path] -m [suffix] Syntax from lib dir: python Install.py -b -m [suffix] specify one or more options, order does not matter -b = download and build MS-CG library -p = specify folder of existing MS-CG installation -m = machine suffix specifies which src/Make/Makefile.suffix to use default suffix = g++_simple Example: make lib-mscg args="-b -m serial " # download/build in lib/mscg/MSCG-release-master with settings compatible with "make serial" make lib-mscg args="-b -m mpi " # download/build in lib/mscg/MSCG-release-master with settings compatible with "make mpi" make lib-mscg args="-p /usr/local/mscg-release " # use existing MS-CG installation in /usr/local/mscg-release """ # settings url = "http://github.com/uchicago-voth/MSCG-release/archive/master.tar.gz" tarfile = "MS-CG-master.tar.gz" tardir = "MSCG-release-master" # 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) - elif which('wget') != None: + 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) - else: error("cannot find 'wget' or 'curl' to download source code") - txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) - return txt + 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() homepath = "." homedir = tardir buildflag = False pathflag = False linkflag = True msuffix = "g++_simple" iarg = 0 while iarg < nargs: if args[iarg] == "-p": if iarg+2 > nargs: error() mscgpath = fullpath(args[iarg+1]) pathflag = True iarg += 2 elif args[iarg] == "-m": if iarg+2 > nargs: error() msuffix = args[iarg+1] iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 else: error() homepath = fullpath(homepath) homedir = "%s/%s" % (homepath,homedir) if (pathflag): if not os.path.isdir(mscgpath): error("MS-CG path does not exist") homedir = mscgpath if (buildflag and pathflag): error("Cannot use -b and -p flag at the same time") if (not buildflag and not pathflag): error("Have to use either -b or -p flag") # download and unpack MS-CG tarfile if buildflag: print("Downloading MS-CG ...") geturl(url,"%s/%s" % (homepath,tarfile)) print("Unpacking MS-CG tarfile ...") if os.path.exists("%s/%s" % (homepath,tardir)): cmd = 'rm -rf "%s/%s"' % (homepath,tardir) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarfile) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.remove("%s/%s" % (homepath,tarfile)) if os.path.basename(homedir) != tardir: if os.path.exists(homedir): cmd = 'rm -rf "%s"' % homedir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.rename("%s/%s" % (homepath,tardir),homedir) # build MS-CG if buildflag: print("Building MS-CG ...") if os.path.exists("%s/src/Make/Makefile.%s" % (homedir,msuffix)): cmd = 'cd "%s/src"; cp Make/Makefile.%s .; make -f Makefile.%s' % \ (homedir,msuffix,msuffix) elif os.path.exists("Makefile.%s" % msuffix): cmd = 'cd "%s/src"; cp ../../Makefile.%s .; make -f Makefile.%s' % \ (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')) if not os.path.exists("Makefile.lammps"): print("Creating Makefile.lammps") if os.path.exists("Makefile.lammps.%s" % msuffix): cmd = 'cp Makefile.lammps.%s Makefile.lammps' % msuffix else: cmd = 'cp Makefile.lammps.default Makefile.lammps' subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) else: print("Makefile.lammps exists. Please check its settings") # create 2 links in lib/mscg to MS-CG src dir if linkflag: print("Creating links to MS-CG 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' % 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) diff --git a/lib/smd/Install.py b/lib/smd/Install.py index 00891339d..9247cb449 100644 --- a/lib/smd/Install.py +++ b/lib/smd/Install.py @@ -1,144 +1,158 @@ #!/usr/bin/env python # Install.py tool to download, unpack, and point to the Eigen library # used to automate the steps described in the README file in this dir from __future__ import print_function import sys,os,re,glob,subprocess # help message help = """ Syntax from src dir: make lib-smd args="-b" or: make lib-smd args="-p /usr/include/eigen3" Syntax from lib dir: python Install.py -b or: python Install.py -p /usr/include/eigen3" or: python Install.py -v 3.3.4 -b specify one or more options, order does not matter -b = download and unpack/configure the Eigen library -p = specify folder holding an existing installation of Eigen -v = set version of Eigen library to download and set up (default = 3.3.4) Example: make lib-smd args="-b" # download/build in default lib/smd/eigen-eigen-* make lib-smd args="-p /usr/include/eigen3" # use existing Eigen installation in /usr/include/eigen3 """ # settings version = '3.3.4' tarball = "eigen.tar.gz" # 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) - elif which('wget') != None: + 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) - else: error("cannot find 'wget' or 'curl' to download source code") - txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) - return txt + 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() homepath = "." homedir = "eigen3" buildflag = False pathflag = False linkflag = True iarg = 0 while iarg < nargs: if args[iarg] == "-v": if iarg+2 > nargs: error() version = args[iarg+1] iarg += 2 elif args[iarg] == "-p": if iarg+2 > nargs: error() eigenpath = fullpath(args[iarg+1]) pathflag = True iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 else: error() homepath = fullpath(homepath) if (pathflag): if not os.path.isdir(eigenpath): error("Eigen path does not exist") if (buildflag and pathflag): error("Cannot use -b and -p flag at the same time") if (not buildflag and not pathflag): error("Have to use either -b or -p flag") # download and unpack Eigen tarball # use glob to find name of dir it unpacks to if buildflag: print("Downloading Eigen ...") url = "http://bitbucket.org/eigen/eigen/get/%s.tar.gz" % version geturl(url,"%s/%s" % (homepath,tarball)) print("Unpacking Eigen tarball ...") edir = glob.glob("%s/eigen-eigen-*" % homepath) for one in edir: if os.path.isdir(one): subprocess.check_output('rm -rf "%s"' % one,stderr=subprocess.STDOUT,shell=True) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) edir = glob.glob("%s/eigen-eigen-*" % homepath) os.rename(edir[0],"%s/%s" % (homepath,homedir)) os.remove(tarball) # create link in lib/smd to Eigen src dir if linkflag: print("Creating link to Eigen files") if os.path.isfile("includelink") or os.path.islink("includelink"): os.remove("includelink") if pathflag: linkdir = eigenpath else: linkdir = "%s/%s" % (homepath,homedir) cmd = 'ln -s "%s" includelink' % linkdir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) diff --git a/lib/voronoi/Install.py b/lib/voronoi/Install.py index 4998358d2..f40eb53bc 100644 --- a/lib/voronoi/Install.py +++ b/lib/voronoi/Install.py @@ -1,155 +1,169 @@ #!/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 from __future__ import print_function import sys,os,re,subprocess # help message help = """ Syntax from src dir: make lib-voronoi args="-b" or: make lib-voronoi args="-p /usr/local/voro++-0.4.6" or: make lib-voronoi args="-b -v voro++-0.4.6" Syntax from lib dir: python Install.py -b -v voro++-0.4.6 or: python Install.py -b or: python Install.py -p /usr/local/voro++-0.4.6 specify one or more options, order does not matter -b = download and build the Voro++ library -p = specify folder of existing Voro++ installation -v = set version of Voro++ to download and build (default voro++-0.4.6) Example: make lib-voronoi args="-b" # download/build in lib/voronoi/voro++-0.4.6 make lib-voronoi args="-p $HOME/voro++-0.4.6" # use existing Voro++ installation in $HOME/voro++-0.4.6 """ # 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)) 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) - elif which('wget') != None: + 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) - else: error("cannot find 'wget' or 'curl' to download source code") - txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) - return txt + 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() homepath = "." homedir = version buildflag = False pathflag = False linkflag = True iarg = 0 while iarg < nargs: if args[iarg] == "-v": if iarg+2 > nargs: error() version = args[iarg+1] iarg += 2 elif args[iarg] == "-p": if iarg+2 > nargs: error() voropath = fullpath(args[iarg+1]) pathflag = True iarg += 2 elif args[iarg] == "-b": buildflag = True iarg += 1 else: error() homepath = fullpath(homepath) homedir = "%s/%s" % (homepath,version) if (pathflag): if not os.path.isdir(voropath): error("Voro++ path does not exist") homedir = voropath if (buildflag and pathflag): error("Cannot use -b and -p flag at the same time") if (not buildflag and not pathflag): error("Have to use either -b or -p flag") # download and unpack Voro++ tarball if buildflag: print("Downloading Voro++ ...") geturl(url,"%s/%s.tar.gz" % (homepath,version)) print("Unpacking Voro++ tarball ...") if os.path.exists("%s/%s" % (homepath,version)): cmd = 'rm -rf "%s/%s"' % (homepath,version) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) 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)) if os.path.basename(homedir) != version: if os.path.exists(homedir): cmd = 'rm -rf "%s"' % homedir subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.rename("%s/%s" % (homepath,version),homedir) # build Voro++ if buildflag: print("Building Voro++ ...") cmd = 'cd "%s"; make CXX=g++ CFLAGS="-fPIC -O3"' % homedir txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print(txt.decode('UTF-8')) # 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' % 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)