Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pbxproj==2.5.1
requests>=2.13
42 changes: 39 additions & 3 deletions toolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,18 @@
import shutil
import fnmatch
import tempfile
import time
from datetime import datetime
try:
from urllib.request import FancyURLopener, urlcleanup
except ImportError:
from urllib import FancyURLopener, urlcleanup

try:
from pbxproj import XcodeProject
from pbxproj.pbxextensions.ProjectFiles import FileOptions
except ImportError:
print("ERROR: pbxproj requirements is missing")
print("ERROR: Python requirements are missing")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why changing this? Should i just say "missing pbxproj" instead?
The rest is good, but i don't understand this

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, an interim version of the fix added the requests import here, so there were 2 packages being imported (learnleapfly@999dc68#diff-c3327fdae2ebcc6a34dc5a9d23ae9ffd) I neglected to change it back (sort of figuring more things might end up in requirements.txt before long)

print("To install: pip install -r requirements.txt")
sys.exit(0)
curdir = dirname(__file__)
Expand All @@ -37,6 +39,7 @@


IS_PY3 = sys.version_info[0] >= 3
IS_PY2 = sys.version_info[0] == 2


def shprint(command, *args, **kwargs):
Expand Down Expand Up @@ -65,7 +68,6 @@ def _cache_execution(self, *args, **kwargs):
state[key_time] = str(datetime.utcnow())
return _cache_execution


class ChromeDownloader(FancyURLopener):
version = (
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 '
Expand Down Expand Up @@ -472,7 +474,41 @@ def report_hook(index, blksize, size):
urlcleanup()

print('Downloading {0}'.format(url))
urlretrieve(url, filename, report_hook)
attempts = 0
while True:
try:
urlretrieve(url, filename, report_hook)
except AttributeError:
if IS_PY2:
# This is caused by bug in python-future, causing occasional
# AttributeError: '_fileobject' object has no attribute 'readinto'
# It can be removed if the upstream fix is accepted. See also:
# * https://github.com/kivy/kivy-ios/issues/322
# * https://github.com/PythonCharmers/python-future/pull/423
import requests

print("Warning: urlretrieve failed. Falling back to request")

headers = {'User-agent': 'Mozilla/5.0 (X11; Linux x86_64) '
'AppleWebKit/537.36 (KHTML, like Gecko) '
'Chrome/28.0.1500.71 Safari/537.36'}
r = requests.get(url, headers=headers)

with open(filename, "wb") as fw:
fw.write(r.content)
break
else:
raise
except OSError as e:
attempts += 1
if attempts >= 5:
print('Max download attempts reached: {}'.format(attempts))
raise e
print('Download failed. Retrying in 1 second...')
time.sleep(1)
continue
break

return filename

def extract_file(self, filename, cwd):
Expand Down