From 146aa4cdbdd3e83a859c1f1f02959904913695bc Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer <akohlmey@gmail.com> Date: Thu, 10 Aug 2017 09:05:23 -0400 Subject: [PATCH] fall back to wget when curl is not available --- lib/kim/Install.py | 23 ++++++++++++++++++++++- lib/mscg/Install.py | 23 ++++++++++++++++++++++- lib/smd/Install.py | 23 ++++++++++++++++++++++- lib/voronoi/Install.py | 23 ++++++++++++++++++++++- 4 files changed, 88 insertions(+), 4 deletions(-) diff --git a/lib/kim/Install.py b/lib/kim/Install.py index 06479d2d4d..21ea859852 100644 --- a/lib/kim/Install.py +++ b/lib/kim/Install.py @@ -60,8 +60,29 @@ def error(str=None): 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): - cmd = 'curl -L -o "%s" %s' % (fname,url) + if which('curl') != None: + cmd = 'curl -L -o "%s" %s' % (fname,url) + elif 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 diff --git a/lib/mscg/Install.py b/lib/mscg/Install.py index e4e5ec5613..154f5aa522 100644 --- a/lib/mscg/Install.py +++ b/lib/mscg/Install.py @@ -47,8 +47,29 @@ def error(str=None): 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): - cmd = 'curl -L -o "%s" %s' % (fname,url) + if which('curl') != None: + cmd = 'curl -L -o "%s" %s' % (fname,url) + elif 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 diff --git a/lib/smd/Install.py b/lib/smd/Install.py index 1c270bea5e..00891339d0 100644 --- a/lib/smd/Install.py +++ b/lib/smd/Install.py @@ -47,8 +47,29 @@ def error(str=None): 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): - cmd = 'curl -L -o "%s" %s' % (fname,url) + if which('curl') != None: + cmd = 'curl -L -o "%s" %s' % (fname,url) + elif 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 diff --git a/lib/voronoi/Install.py b/lib/voronoi/Install.py index a4d07ac745..4998358d27 100644 --- a/lib/voronoi/Install.py +++ b/lib/voronoi/Install.py @@ -46,8 +46,29 @@ def error(str=None): 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): - cmd = 'curl -L -o "%s" %s' % (fname,url) + if which('curl') != None: + cmd = 'curl -L -o "%s" %s' % (fname,url) + elif 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 -- GitLab