make download function more resilient by also catching failed execution
This commit is contained in:
@ -6,6 +6,8 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import sys,os,re,subprocess
|
import sys,os,re,subprocess
|
||||||
|
|
||||||
|
# help message
|
||||||
|
|
||||||
help = """
|
help = """
|
||||||
Syntax from src dir: make lib-kim args="-b -v version -a kim-name"
|
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="-b -a everything"
|
||||||
@ -23,7 +25,7 @@ specify one or more options, order does not matter
|
|||||||
-b = download and build base KIM API library with example Models
|
-b = download and build base KIM API library with example Models
|
||||||
this will delete any previous installation in the current folder
|
this will delete any previous installation in the current folder
|
||||||
-n = do NOT download and build base KIM API library.
|
-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)
|
-p = specify location of KIM API installation (implies -n)
|
||||||
-a = add single KIM model or model driver with kim-name
|
-a = add single KIM model or model driver with kim-name
|
||||||
to existing KIM API lib (see example below).
|
to existing KIM API lib (see example below).
|
||||||
@ -78,13 +80,27 @@ def which(program):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def geturl(url,fname):
|
def geturl(url,fname):
|
||||||
|
success = False
|
||||||
|
|
||||||
if which('curl') != None:
|
if which('curl') != None:
|
||||||
cmd = 'curl -L -o "%s" %s' % (fname,url)
|
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)
|
cmd = 'wget -O "%s" %s' % (fname,url)
|
||||||
else: error("cannot find 'wget' or 'curl' to download source code")
|
try:
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
return txt
|
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
|
# parse args
|
||||||
|
|
||||||
|
|||||||
@ -65,13 +65,27 @@ def which(program):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def geturl(url,fname):
|
def geturl(url,fname):
|
||||||
|
success = False
|
||||||
|
|
||||||
if which('curl') != None:
|
if which('curl') != None:
|
||||||
cmd = 'curl -L -o "%s" %s' % (fname,url)
|
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)
|
cmd = 'wget -O "%s" %s' % (fname,url)
|
||||||
else: error("cannot find 'wget' or 'curl' to download source code")
|
try:
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
return txt
|
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
|
# parse args
|
||||||
|
|
||||||
|
|||||||
@ -65,13 +65,27 @@ def which(program):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def geturl(url,fname):
|
def geturl(url,fname):
|
||||||
|
success = False
|
||||||
|
|
||||||
if which('curl') != None:
|
if which('curl') != None:
|
||||||
cmd = 'curl -L -o "%s" %s' % (fname,url)
|
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)
|
cmd = 'wget -O "%s" %s' % (fname,url)
|
||||||
else: error("cannot find 'wget' or 'curl' to download source code")
|
try:
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
return txt
|
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
|
# parse args
|
||||||
|
|
||||||
|
|||||||
@ -64,13 +64,27 @@ def which(program):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def geturl(url,fname):
|
def geturl(url,fname):
|
||||||
|
success = False
|
||||||
|
|
||||||
if which('curl') != None:
|
if which('curl') != None:
|
||||||
cmd = 'curl -L -o "%s" %s' % (fname,url)
|
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)
|
cmd = 'wget -O "%s" %s' % (fname,url)
|
||||||
else: error("cannot find 'wget' or 'curl' to download source code")
|
try:
|
||||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
|
||||||
return txt
|
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
|
# parse args
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user