You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.4 KiB
36 lines
1.4 KiB
"""EasyEngine download core classes."""
|
|
import urllib.request
|
|
import urllib.error
|
|
import os
|
|
|
|
|
|
class EEDownload():
|
|
"""Method to download using urllib"""
|
|
def __init__():
|
|
pass
|
|
|
|
def download(self, packages):
|
|
for package in packages:
|
|
url = package[0]
|
|
filename = package[1]
|
|
try:
|
|
directory = os.path.dirname(filename)
|
|
if not os.path.exists(directory):
|
|
os.makedirs(directory)
|
|
self.app.log.info("Downloading "+os.path.basename(url)+" ...")
|
|
urllib.request.urlretrieve(url, filename)
|
|
self.app.log.info("Done")
|
|
except urllib.error.URLError as e:
|
|
self.app.log.info("Unable to donwload file, [{err}]"
|
|
.format(err=str(e.reason)))
|
|
return False
|
|
except urllib.error.HTTPError as e:
|
|
self.app.log.error("Package download failed. [{err}]"
|
|
.format(err=str(e.reason)))
|
|
return False
|
|
except urllib.error.ContentTooShortError as e:
|
|
self.app.log.error("Package download failed. The amount of the"
|
|
" downloaded data is less than "
|
|
"the expected amount \{0} {1}"
|
|
.format(e.errno, e.strerror))
|
|
return False
|
|
|