Skip to content

Commit

Permalink
Fix download from sourceforge (and possibly many others) (#830)
Browse files Browse the repository at this point in the history
  • Loading branch information
misl6 authored Jul 16, 2023
1 parent 9807f6e commit f10918c
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions kivy_ios/toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@
from datetime import datetime
from pprint import pformat
import logging
from urllib.request import FancyURLopener, urlcleanup
import urllib.request
from pbxproj import XcodeProject
from pbxproj.pbxextensions.ProjectFiles import FileOptions

url_opener = urllib.request.build_opener()
url_orig_headers = url_opener.addheaders
urllib.request.install_opener(url_opener)

curdir = dirname(__file__)

initial_working_directory = getcwd()
Expand Down Expand Up @@ -86,15 +90,6 @@ def remove_junk(d):
unlink(join(root, fn))


class ChromeDownloader(FancyURLopener):
version = (
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 '
'(KHTML, like Gecko) Chrome/28.0.1500.71 Safari/537.36')


urlretrieve = ChromeDownloader().retrieve


class JsonStore:
"""Replacement of shelve using json, needed for support python 2 and 3.
"""
Expand Down Expand Up @@ -468,13 +463,14 @@ def report_hook(index, blksize, size):
unlink(filename)

# Clean up temporary files just in case before downloading.
urlcleanup()
urllib.request.urlcleanup()

logger.info('Downloading {0}'.format(url))
attempts = 0
while True:
try:
urlretrieve(url, filename, report_hook)
url_opener.addheaders = [('User-agent', 'Wget/1.0')]
urllib.request.urlretrieve(url, filename, report_hook)
except OSError:
attempts += 1
if attempts >= 5:
Expand All @@ -483,6 +479,8 @@ def report_hook(index, blksize, size):
logger.warning('Download failed. Retrying in 1 second...')
time.sleep(1)
continue
finally:
url_opener.addheaders = url_orig_headers
break

return filename
Expand Down

0 comments on commit f10918c

Please sign in to comment.