1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

now returns false on bad role_data

This commit is contained in:
Brian Coca 2015-07-29 19:48:21 -04:00
parent e81ec32719
commit 8153c34abf

View file

@ -182,28 +182,30 @@ class GalaxyRole(object):
""" """
Downloads the archived role from github to a temp location Downloads the archived role from github to a temp location
""" """
if role_data:
# first grab the file and save it to a temp location # first grab the file and save it to a temp location
if "github_user" in role_data and "github_repo" in role_data: if "github_user" in role_data and "github_repo" in role_data:
archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], self.version) archive_url = 'https://github.com/%s/%s/archive/%s.tar.gz' % (role_data["github_user"], role_data["github_repo"], self.version)
else: else:
archive_url = self.src archive_url = self.src
self.display.display("- downloading role from %s" % archive_url) self.display.display("- downloading role from %s" % archive_url)
try: try:
url_file = urlopen(archive_url) url_file = urlopen(archive_url)
temp_file = tempfile.NamedTemporaryFile(delete=False) temp_file = tempfile.NamedTemporaryFile(delete=False)
data = url_file.read()
while data:
temp_file.write(data)
data = url_file.read() data = url_file.read()
temp_file.close() while data:
return temp_file.name temp_file.write(data)
except: data = url_file.read()
# TODO: better urllib2 error handling for error temp_file.close()
# messages that are more exact return temp_file.name
self.display.error("failed to download the file.") except:
return False # TODO: better urllib2 error handling for error
# messages that are more exact
self.display.error("failed to download the file.")
return False
def install(self, role_filename): def install(self, role_filename):
# the file is a tar, so open it that way and extract it # the file is a tar, so open it that way and extract it