diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-09-23 21:29:03 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-09-23 21:29:03 -0400 |
commit | ce3c43cbd5e2c08ec63e6765fca8c590dd4df2b4 (patch) | |
tree | 1f4844f00a8fc3f6f06e0597f2f37df8549a507a /ez_setup.py | |
parent | b77de7a697926a3b1d757062f8c2bae35f6e915b (diff) | |
download | external_python_setuptools-ce3c43cbd5e2c08ec63e6765fca8c590dd4df2b4.tar.gz external_python_setuptools-ce3c43cbd5e2c08ec63e6765fca8c590dd4df2b4.tar.bz2 external_python_setuptools-ce3c43cbd5e2c08ec63e6765fca8c590dd4df2b4.zip |
extract _clean_check call
Diffstat (limited to 'ez_setup.py')
-rw-r--r-- | ez_setup.py | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/ez_setup.py b/ez_setup.py index 16b8016d..c3069e7a 100644 --- a/ez_setup.py +++ b/ez_setup.py @@ -151,6 +151,18 @@ def use_setuptools(version=DEFAULT_VERSION, download_base=DEFAULT_URL, return _do_download(version, download_base, to_dir, download_delay) +def _clean_check(cmd, target): + """ + Run the command to download target. If the command fails, clean up before + re-raising the error. + """ + try: + subprocess.check_call(cmd) + except subprocess.CalledProcessError: + if os.access(target, os.F_OK): + os.unlink(target) + raise + def download_file_powershell(url, target): """ Download the file at url to target using Powershell (which will validate @@ -162,12 +174,7 @@ def download_file_powershell(url, target): '-Command', "(new-object System.Net.WebClient).DownloadFile(%(url)r, %(target)r)" % vars(), ] - try: - subprocess.check_call(cmd) - except subprocess.CalledProcessError: - if os.access(target, os.F_OK): - os.unlink(target) - raise + _clean_check(cmd, target) def has_powershell(): if platform.system() != 'Windows': @@ -187,12 +194,7 @@ download_file_powershell.viable = has_powershell def download_file_curl(url, target): cmd = ['curl', url, '--silent', '--output', target] - try: - subprocess.check_call(cmd) - except subprocess.CalledProcessError: - if os.access(target, os.F_OK): - os.unlink(target) - raise + _clean_check(cmd, target) def has_curl(): cmd = ['curl', '--version'] @@ -210,12 +212,7 @@ download_file_curl.viable = has_curl def download_file_wget(url, target): cmd = ['wget', url, '--quiet', '--output-document', target] - try: - subprocess.check_call(cmd) - except subprocess.CalledProcessError: - if os.access(target, os.F_OK): - os.unlink(target) - raise + _clean_check(cmd, target) def has_wget(): cmd = ['wget', '--version'] |