From eda79bd1c2363f4e43f42a4600e79f85aa3f1f92 Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Wed, 28 Nov 2018 20:46:50 -0500 Subject: [PATCH] use shutil.rmtree() instead of calling 'rm -rf' for increased portability --- lib/gpu/Install.py | 4 ++-- lib/kim/Install.py | 5 ++--- lib/latte/Install.py | 5 ++--- lib/mscg/Install.py | 8 +++----- lib/plumed/Install.py | 8 +++----- lib/scafacos/Install.py | 8 +++----- lib/smd/Install.py | 4 ++-- lib/voronoi/Install.py | 8 +++----- 8 files changed, 20 insertions(+), 30 deletions(-) diff --git a/lib/gpu/Install.py b/lib/gpu/Install.py index d1024c0085..14549f53b8 100644 --- a/lib/gpu/Install.py +++ b/lib/gpu/Install.py @@ -143,8 +143,8 @@ fp.close() if makeflag: print("Building libgpu.a ...") - cmd = "rm -f libgpu.a" - subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + if os.path.exists("libgpu.a"): + os.remove("libgpu.a") cmd = "make -f Makefile.auto clean; make -f Makefile.auto" txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) print(txt.decode('UTF-8')) diff --git a/lib/kim/Install.py b/lib/kim/Install.py index d098250906..6cc1a1abc2 100644 --- a/lib/kim/Install.py +++ b/lib/kim/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,subprocess +import sys,os,re,subprocess,shutil # help message @@ -177,8 +177,7 @@ if buildflag: 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) + shutil.rmtree(kimdir) # configure LAMMPS to use kim-api to be installed diff --git a/lib/latte/Install.py b/lib/latte/Install.py index 1e1f3040c2..07f89e9150 100644 --- a/lib/latte/Install.py +++ b/lib/latte/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,subprocess,hashlib +import sys,os,re,subprocess,hashlib,shutil # help message @@ -167,8 +167,7 @@ if buildflag: print("Unpacking LATTE ...") if os.path.exists(lattedir): - cmd = 'rm -rf "%s"' % lattedir - subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + shutil.rmtree(lattedir) cmd = 'cd "%s"; tar zxvf LATTE.tar.gz' % lattepath subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.remove("%s/LATTE.tar.gz" % lattepath) diff --git a/lib/mscg/Install.py b/lib/mscg/Install.py index ec70f13f6e..d613532d39 100644 --- a/lib/mscg/Install.py +++ b/lib/mscg/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,subprocess +import sys,os,re,subprocess,shutil # help message @@ -139,15 +139,13 @@ if buildflag: 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) + shutil.rmtree("%s/%s" % (homepath,tardir)) 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) + shutil.rmtree(homedir) os.rename("%s/%s" % (homepath,tardir),homedir) # build MS-CG diff --git a/lib/plumed/Install.py b/lib/plumed/Install.py index cbe3a55937..8d844678cd 100644 --- a/lib/plumed/Install.py +++ b/lib/plumed/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,subprocess,hashlib +import sys,os,re,subprocess,hashlib,shutil # help message @@ -169,11 +169,9 @@ if buildflag: print("Unpacking plumed2 source tarball ...") if os.path.exists("%s/plumed-%s" % (homepath,version)): - cmd = 'rm -rf "%s/plumed-%s"' % (homepath,version) - subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + shutil.rmtree("%s/plumed-%s" % (homepath,version)) if os.path.exists(homedir): - cmd = 'rm -rf "%s"' % (homedir) - subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) + shutil.rmtree(homedir) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,filename) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) os.remove("%s/%s" % (homepath,filename)) diff --git a/lib/scafacos/Install.py b/lib/scafacos/Install.py index d23e8a3686..8e342ad1ba 100644 --- a/lib/scafacos/Install.py +++ b/lib/scafacos/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,subprocess +import sys,os,re,subprocess,shutil # help message @@ -132,15 +132,13 @@ if buildflag: print("Unpacking Scafacos 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) + shutil.rmtree("%s/%s" % (homepath,version)) 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) + shutil.rmtree(homedir) os.rename("%s/%s" % (homepath,version),homedir) # build Scafacos diff --git a/lib/smd/Install.py b/lib/smd/Install.py index 9247cb449b..8d83b0f78a 100644 --- a/lib/smd/Install.py +++ b/lib/smd/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,glob,subprocess +import sys,os,re,glob,subprocess,shutil # help message @@ -139,7 +139,7 @@ if buildflag: 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) + shutil.rmtree(one) cmd = 'cd "%s"; tar -xzvf %s' % (homepath,tarball) subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True) edir = glob.glob("%s/eigen-eigen-*" % homepath) diff --git a/lib/voronoi/Install.py b/lib/voronoi/Install.py index f40eb53bc6..4e8b457905 100644 --- a/lib/voronoi/Install.py +++ b/lib/voronoi/Install.py @@ -4,7 +4,7 @@ # used to automate the steps described in the README file in this dir from __future__ import print_function -import sys,os,re,subprocess +import sys,os,re,subprocess,shutil # help message @@ -136,15 +136,13 @@ if buildflag: 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) + shutil.rmtree("%s/%s" % (homepath,version)) 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) + shutil.rmtree(homedir) os.rename("%s/%s" % (homepath,version),homedir) # build Voro++