Skip to content

Commit

Permalink
Refs #7830 - Use simpler test for cURL.
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterParker committed Oct 8, 2013
1 parent ce1cde9 commit 87e08ed
Showing 1 changed file with 16 additions and 27 deletions.
43 changes: 16 additions & 27 deletions Code/Tools/DOI/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,34 +294,23 @@ def check_if_doi_exists(base, doi, destination, options):
"Unexpected result back from server: \"" + result[0] + "\"")

def check_for_curl():
'''A check to see whether we can call cURL on the command line. Based on
an implementation of "which" found at http://stackoverflow.com/a/379535.
If cURL cannot be called an exception will be raised, else the script will
be free to continue.
This appears to work on both Linux and Windows.
'''A check to see whether we can call cURL on the command line.
'''
def is_exe(fpath):
return os.path.exists(fpath) and os.access(fpath, os.X_OK)

def ext_candidates(fpath):
yield fpath
for ext in os.environ.get("PATHEXT", "").split(os.pathsep):
yield fpath + ext

fpath, fname = os.path.split("curl")
if fpath:
if is_exe("curl"):
return # Found cURL.
else:
for path in os.environ["PATH"].split(os.pathsep):
exe_file = os.path.join(path, "curl")
for candidate in ext_candidates(exe_file):
if is_exe(candidate):
return # Found cURL.

raise Exception('This script requires that cURL be installed and ' + \
'available on the PATH.')
# See if a call to 'curl --version' gives us a successful return code,
# else raise an exception.
try:
proc = subprocess.Popen(['curl', '--version'],stdout=subprocess.PIPE)
proc.wait()
if proc.returncode == 0:
found = True
else:
found = False
except:
found = False

if not found:
raise Exception('This script requires that cURL be installed and ' + \
'available on the PATH.')

def run(options):
'''Creating a usable DOI is (for our purposes at least) a two step
Expand Down

0 comments on commit 87e08ed

Please sign in to comment.