Created
July 2, 2014 04:55
-
-
Save k-okada/cf79038d1cffc943a8d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from rosdep2.main import rosdep_main | |
import rosdep2 | |
from rosdep2.sources_list import * | |
from urllib import * | |
from urllib2 import * | |
DEFAULT_SOURCES_LIST_URL = 'https://raw.github.com/ros/rosdistro/master/rosdep/sources.list.d/20-default.list' | |
DOWNLOAD_TIMEOUT = 15.0 | |
import urllib2 | |
def download_default_sources_list(url=DEFAULT_SOURCES_LIST_URL): | |
""" | |
Download (and validate) contents of default sources list. | |
:param url: override URL of default sources list file | |
:return: raw sources list data, ``str`` | |
:raises: :exc:`InvalidData` | |
:raises: :exc:`urllib2.URLError` If data cannot be | |
retrieved (e.g. 404, server down). | |
""" | |
try: | |
# check for http[s]?_proxy user | |
o = urlparse.urlparse(url) | |
if os.environ.has_key(o.scheme+'_proxy') : | |
proxy = urllib2.ProxyHandler({o.scheme: os.environ[o.scheme+'_proxy']}) | |
auth = urllib2.HTTPBasicAuthHandler() | |
opener = urllib2.build_opener(proxy, auth, urllib2.HTTPHandler) | |
urllib2.install_opener(opener) | |
f = urlopen(url, timeout=DOWNLOAD_TIMEOUT) | |
except (URLError, httplib.HTTPException) as e: | |
raise URLError(str(e) + ' (%s)' % url) | |
data = f.read().decode() | |
f.close() | |
if not data: | |
raise InvalidSourceFile("cannot download defaults file: empty contents") | |
# parse just for validation | |
parse_sources_data(data) | |
return data | |
rosdep2.main.download_default_sources_list = download_default_sources_list | |
rosdep_main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment