Skip to content
Closed
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
35 changes: 21 additions & 14 deletions download-deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
****************************************************************************"""

import os.path
from urllib.error import HTTPError
import zipfile
import shutil
import sys
Expand Down Expand Up @@ -110,7 +111,10 @@ def __init__(self, workpath, config_path, version_path, remote_version_key=None)
print("==> version file doesn't exist")

def get_input_value(self, prompt):
ret = raw_input(prompt)
if(python_2):
ret = raw_input(prompt)
else:
ret = input(prompt)
ret.rstrip(" \t")
return ret

Expand All @@ -121,18 +125,26 @@ def download_file(self):
except OSError:
pass
print("==> Ready to download '%s' from '%s'" % (self._filename, self._url))
import urllib2
if(python_2):
import urllib2 as urllib
else:
import urllib.request as urllib
try:
u = urllib2.urlopen(self._url)
except urllib2.HTTPError as e:
u = urllib.urlopen(self._url)
except Exception as e:
if e.code == 404:
print("==> Error: Could not find the file from url: '%s'" % (self._url))
print("==> Http request failed, error code: " + str(e.code) + ", reason: " + e.read())
print("==> Http request failed, error code: " + str(e.code) + ", reason: " + str(e.read()))
sys.exit(1)

f = open(self._filename, 'wb')
meta = u.info()
content_len = meta.getheaders("Content-Length")
content_len = 0
if(python_2):
content_len = meta.getheaders("Content-Length")
else:
content_len = meta['Content-Length']

file_size = 0
if content_len and len(content_len) > 0:
file_size = int(content_len[0])
Expand Down Expand Up @@ -246,7 +258,6 @@ def download_zip_file(self):
self.download_zip_file()

def download_file_with_retry(self, times, delay):
import urllib2
times_count = 0
while(times_count < times):
times_count += 1
Expand Down Expand Up @@ -339,22 +350,17 @@ def run(self, workpath, folder_for_extracting, remove_downloaded, force_update,
print("==> Download (%s) finish!" % self._filename)


def _check_python_version():
def _is_python_version_2():
major_ver = sys.version_info[0]
print ("The python version is %d.%d." % (major_ver, sys.version_info[1]))
if major_ver > 2:
print ("The python version is %d.%d. But python 2.x is required. (Version 2.7 is well tested)\n"
"Download it here: https://www.python.org/" % (major_ver, sys.version_info[1]))
return False

return True


def main():
workpath = os.path.dirname(os.path.realpath(__file__))

if not _check_python_version():
exit()

parser = OptionParser()
parser.add_option('-r', '--remove-download',
action="store", type="string", dest='remove_downloaded', default=None,
Expand All @@ -378,6 +384,7 @@ def main():

# -------------- main --------------
if __name__ == '__main__':
python_2 = _is_python_version_2()
try:
main()
except Exception as e:
Expand Down