Skip to content

Commit

Permalink
add logging to connection
Browse files Browse the repository at this point in the history
  • Loading branch information
kalefranz committed Aug 3, 2016
1 parent 5d2629b commit 84d3ea5
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions conda/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from . import __version__ as VERSION
from .base.constants import DEFAULT_CHANNEL_ALIAS
from .base.context import context, platform as context_platform
from .common.io import disable_logger
from .common.io import disable_logger, captured
from .common.url import url_to_path, url_to_s3_info, urlparse
from .compat import StringIO
from .exceptions import AuthenticationError
Expand Down Expand Up @@ -75,13 +75,15 @@ def add_binstar_token(url):
token = BinstarAuth.get_binstar_token(url)
if token is None:
return url
log.debug("Adding binstar token to url %s", url)
u = urlparse(url)
path = u.path if u.path.startswith('/t/') else "/t/%s/%s" % (token, u.path.lstrip('/'))
return Url(u.scheme, u.auth, u.host, u.port, path, u.query).url

@staticmethod
def get_binstar_token(url):
try:
log.debug("Attempting to binstar collect token for url %s", url)
try:
from binstar_client.utils import get_config, load_token
except ImportError:
Expand All @@ -93,12 +95,13 @@ def get_binstar_token(url):
base_url = '%s://%s' % (url_parts.scheme, url_parts.netloc)
if DEFAULT_CHANNEL_ALIAS.startswith(base_url):
base_url = binstar_default_url

with disable_logger('binstar'):
with disable_logger('binstar'), captured() as c:
config = get_config(remote_site=base_url)
url_from_bs_config = config.get('url', base_url)
token = load_token(url_from_bs_config)
return token
log.debug("binstar stdout >> %s\n"
"binstar stderr >> %s", c.stdout, c.stderr)
return token
except Exception as e:
log.warn("Warning: could not capture token from anaconda-client (%r)", e)
return None
Expand Down Expand Up @@ -134,6 +137,9 @@ def __init__(self, *args, **kwargs):
# Enable file:// urls
self.mount("file://", LocalFSAdapter())

# Enable ftp:// urls
self.mount("ftp://", FTPAdapter())

# Enable s3:// urls
self.mount("s3://", S3Adapter())

Expand All @@ -148,8 +154,7 @@ def __init__(self):
super(S3Adapter, self).__init__()
self._temp_file = None

def send(self, request, stream=None, timeout=None, verify=None, cert=None,
proxies=None):
def send(self, request, stream=None, timeout=None, verify=None, cert=None, proxies=None):

resp = requests.models.Response()
resp.status_code = 200
Expand Down Expand Up @@ -223,8 +228,7 @@ def close(self):

class LocalFSAdapter(requests.adapters.BaseAdapter):

def send(self, request, stream=None, timeout=None, verify=None, cert=None,
proxies=None):
def send(self, request, stream=None, timeout=None, verify=None, cert=None, proxies=None):
pathname = url_to_path(request.url)

resp = requests.models.Response()
Expand Down

0 comments on commit 84d3ea5

Please sign in to comment.