use shutil.rmtree() instead of calling 'rm -rf' for increased portability

This commit is contained in:
Axel Kohlmeyer
2018-11-28 20:46:50 -05:00
parent a4d21370bf
commit eda79bd1c2
8 changed files with 20 additions and 30 deletions

View File

@ -143,8 +143,8 @@ fp.close()
if makeflag: if makeflag:
print("Building libgpu.a ...") print("Building libgpu.a ...")
cmd = "rm -f libgpu.a" if os.path.exists("libgpu.a"):
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.remove("libgpu.a")
cmd = "make -f Makefile.auto clean; make -f Makefile.auto" cmd = "make -f Makefile.auto clean; make -f Makefile.auto"
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
print(txt.decode('UTF-8')) print(txt.decode('UTF-8'))

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess import sys,os,re,subprocess,shutil
# help message # help message
@ -177,8 +177,7 @@ if buildflag:
if os.path.isdir(kimdir): if os.path.isdir(kimdir):
print("kim-api is already installed at %s.\nRemoving it for re-install" % kimdir) print("kim-api is already installed at %s.\nRemoving it for re-install" % kimdir)
cmd = 'rm -rf "%s"' % kimdir shutil.rmtree(kimdir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
# configure LAMMPS to use kim-api to be installed # configure LAMMPS to use kim-api to be installed

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess,hashlib import sys,os,re,subprocess,hashlib,shutil
# help message # help message
@ -167,8 +167,7 @@ if buildflag:
print("Unpacking LATTE ...") print("Unpacking LATTE ...")
if os.path.exists(lattedir): if os.path.exists(lattedir):
cmd = 'rm -rf "%s"' % lattedir shutil.rmtree(lattedir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar zxvf LATTE.tar.gz' % lattepath cmd = 'cd "%s"; tar zxvf LATTE.tar.gz' % lattepath
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/LATTE.tar.gz" % lattepath) os.remove("%s/LATTE.tar.gz" % lattepath)

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess import sys,os,re,subprocess,shutil
# help message # help message
@ -139,15 +139,13 @@ if buildflag:
print("Unpacking MS-CG tarfile ...") print("Unpacking MS-CG tarfile ...")
if os.path.exists("%s/%s" % (homepath,tardir)): if os.path.exists("%s/%s" % (homepath,tardir)):
cmd = 'rm -rf "%s/%s"' % (homepath,tardir) shutil.rmtree("%s/%s" % (homepath,tardir))
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarfile) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarfile)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/%s" % (homepath,tarfile)) os.remove("%s/%s" % (homepath,tarfile))
if os.path.basename(homedir) != tardir: if os.path.basename(homedir) != tardir:
if os.path.exists(homedir): if os.path.exists(homedir):
cmd = 'rm -rf "%s"' % homedir shutil.rmtree(homedir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.rename("%s/%s" % (homepath,tardir),homedir) os.rename("%s/%s" % (homepath,tardir),homedir)
# build MS-CG # build MS-CG

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess,hashlib import sys,os,re,subprocess,hashlib,shutil
# help message # help message
@ -169,11 +169,9 @@ if buildflag:
print("Unpacking plumed2 source tarball ...") print("Unpacking plumed2 source tarball ...")
if os.path.exists("%s/plumed-%s" % (homepath,version)): if os.path.exists("%s/plumed-%s" % (homepath,version)):
cmd = 'rm -rf "%s/plumed-%s"' % (homepath,version) shutil.rmtree("%s/plumed-%s" % (homepath,version))
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
if os.path.exists(homedir): if os.path.exists(homedir):
cmd = 'rm -rf "%s"' % (homedir) shutil.rmtree(homedir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,filename) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,filename)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/%s" % (homepath,filename)) os.remove("%s/%s" % (homepath,filename))

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess import sys,os,re,subprocess,shutil
# help message # help message
@ -132,15 +132,13 @@ if buildflag:
print("Unpacking Scafacos tarball ...") print("Unpacking Scafacos tarball ...")
if os.path.exists("%s/%s" % (homepath,version)): if os.path.exists("%s/%s" % (homepath,version)):
cmd = 'rm -rf "%s/%s"' % (homepath,version) shutil.rmtree("%s/%s" % (homepath,version))
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version) cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/%s.tar.gz" % (homepath,version)) os.remove("%s/%s.tar.gz" % (homepath,version))
if os.path.basename(homedir) != version: if os.path.basename(homedir) != version:
if os.path.exists(homedir): if os.path.exists(homedir):
cmd = 'rm -rf "%s"' % homedir shutil.rmtree(homedir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.rename("%s/%s" % (homepath,version),homedir) os.rename("%s/%s" % (homepath,version),homedir)
# build Scafacos # build Scafacos

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,glob,subprocess import sys,os,re,glob,subprocess,shutil
# help message # help message
@ -139,7 +139,7 @@ if buildflag:
edir = glob.glob("%s/eigen-eigen-*" % homepath) edir = glob.glob("%s/eigen-eigen-*" % homepath)
for one in edir: for one in edir:
if os.path.isdir(one): if os.path.isdir(one):
subprocess.check_output('rm -rf "%s"' % one,stderr=subprocess.STDOUT,shell=True) shutil.rmtree(one)
cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
edir = glob.glob("%s/eigen-eigen-*" % homepath) edir = glob.glob("%s/eigen-eigen-*" % homepath)

View File

@ -4,7 +4,7 @@
# used to automate the steps described in the README file in this dir # used to automate the steps described in the README file in this dir
from __future__ import print_function from __future__ import print_function
import sys,os,re,subprocess import sys,os,re,subprocess,shutil
# help message # help message
@ -136,15 +136,13 @@ if buildflag:
print("Unpacking Voro++ tarball ...") print("Unpacking Voro++ tarball ...")
if os.path.exists("%s/%s" % (homepath,version)): if os.path.exists("%s/%s" % (homepath,version)):
cmd = 'rm -rf "%s/%s"' % (homepath,version) shutil.rmtree("%s/%s" % (homepath,version))
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version) cmd = 'cd "%s"; tar -xzvf %s.tar.gz' % (homepath,version)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.remove("%s/%s.tar.gz" % (homepath,version)) os.remove("%s/%s.tar.gz" % (homepath,version))
if os.path.basename(homedir) != version: if os.path.basename(homedir) != version:
if os.path.exists(homedir): if os.path.exists(homedir):
cmd = 'rm -rf "%s"' % homedir shutil.rmtree(homedir)
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
os.rename("%s/%s" % (homepath,version),homedir) os.rename("%s/%s" % (homepath,version),homedir)
# build Voro++ # build Voro++