From 03cd4c5255573463cfc5448a87cdc870364b5ed7 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer <akohlmey@gmail.com> Date: Tue, 18 Jul 2017 17:16:10 -0400 Subject: [PATCH] ported lib/voronoi/Install.py to python 3.x and tested with 2.7 --- lib/voronoi/Install.py | 57 +++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/lib/voronoi/Install.py b/lib/voronoi/Install.py index 54246f113e..64122c9d5b 100644 --- a/lib/voronoi/Install.py +++ b/lib/voronoi/Install.py @@ -2,8 +2,10 @@ # 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 +from __future__ import print_function +import sys,os,re,subprocess +try: from urllib.request import urlretrieve as geturl +except: from urllib import urlretrieve as geturl # help message @@ -39,8 +41,8 @@ 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 + if not str: print(help) + else: print("ERROR",str) sys.exit() # expand to full path name @@ -58,9 +60,9 @@ if nargs == 0: error() homepath = "." homedir = version -grabflag = 0 -buildflag = 0 -linkflag = 0 +grabflag = False +buildflag = False +linkflag = False iarg = 0 while iarg < nargs: @@ -74,13 +76,13 @@ while iarg < nargs: homedir = args[iarg+2] iarg += 3 elif args[iarg] == "-g": - grabflag = 1 + grabflag = True iarg += 1 elif args[iarg] == "-b": - buildflag = 1 + buildflag = True iarg += 1 elif args[iarg] == "-l": - linkflag = 1 + linkflag = True iarg += 1 else: error() @@ -91,35 +93,38 @@ homedir = "%s/%s" % (homepath,homedir) # download and unpack Voro++ tarball if grabflag: - print "Downloading Voro++ ..." - urllib.urlretrieve(url,"%s/%s.tar.gz" % (homepath,version)) + print("Downloading Voro++ ...") + geturl(url,"%s/%s.tar.gz" % (homepath,version)) - print "Unpacking Voro++ tarball ..." + print("Unpacking Voro++ tarball ...") if os.path.exists("%s/%s" % (homepath,version)): - commands.getoutput("rm -rf %s/%s" % (homepath,version)) - cmd = "cd %s; tar zxvf %s.tar.gz" % (homepath,version) - commands.getoutput(cmd) + cmd = ['rm -rf "%s/%s"' % (homepath,version)] + subprocess.check_output(cmd,shell=True) + cmd = ['cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version)] + subprocess.check_output(cmd,shell=True) if os.path.basename(homedir) != version: - if os.path.exists(homedir): commands.getoutput("rm -rf %s" % homedir) + if os.path.exists(homedir): + cmd = ['rm -rf "%s"' % homedir] + subprocess.check_output(cmd,shell=True) os.rename("%s/%s" % (homepath,version),homedir) # build Voro++ if buildflag: - print "Building Voro++ ..." - cmd = "cd %s; make" % homedir - txt = commands.getoutput(cmd) - print txt + print("Building Voro++ ...") + cmd = ['cd "%s"; make' % homedir] + txt = subprocess.check_output(cmd,shell=True) + print(txt) # create 2 links in lib/voronoi to Voro++ src dir if linkflag: - print "Creating links to Voro++ include and lib files" + 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 - commands.getoutput(cmd) - cmd = "ln -s %s/src liblink" % homedir - commands.getoutput(cmd) + cmd = ['ln -s "%s/src" includelink' % homedir, 'includelink'] + subprocess.check_output(cmd,shell=True) + cmd = ['ln -s "%s/src" liblink' % homedir] + subprocess.check_output(cmd,shell=True) -- GitLab