Commit c6d923b6 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

make download function more resilient by also catching failed execution

parent 6d24be8b
Loading
Loading
Loading
Loading
+21 −5
Original line number Diff line number Diff line
@@ -6,6 +6,8 @@
from __future__ import print_function
import sys,os,re,subprocess

# help message

help = """
Syntax from src dir: make lib-kim args="-b -v version  -a kim-name"
                 or: make lib-kim args="-b -a everything"
@@ -78,13 +80,27 @@ def which(program):
  return None

def geturl(url,fname):
  success = False

  if which('curl') != None:
    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)
  else: error("cannot find 'wget' or 'curl' to download source code")
  txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  return txt
    try:
      subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
      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

+18 −4
Original line number Diff line number Diff line
@@ -65,13 +65,27 @@ def which(program):
  return None

def geturl(url,fname):
  success = False

  if which('curl') != None:
    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)
  else: error("cannot find 'wget' or 'curl' to download source code")
  txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  return txt
    try:
      subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
      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

+18 −4
Original line number Diff line number Diff line
@@ -65,13 +65,27 @@ def which(program):
  return None

def geturl(url,fname):
  success = False

  if which('curl') != None:
    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)
  else: error("cannot find 'wget' or 'curl' to download source code")
  txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  return txt
    try:
      subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
      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

+18 −4
Original line number Diff line number Diff line
@@ -64,13 +64,27 @@ def which(program):
  return None

def geturl(url,fname):
  success = False

  if which('curl') != None:
    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)
  else: error("cannot find 'wget' or 'curl' to download source code")
  txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
  return txt
    try:
      subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True)
      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