Skip to content

Commit

Permalink
cleaned up some logging messages
Browse files Browse the repository at this point in the history
  • Loading branch information
ijiraq committed Feb 1, 2015
1 parent c9f6bbc commit 7442d2c
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions vos/vos.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import hashlib
from contextlib import nested
from cStringIO import StringIO
import ssl
import html2text
import httplib
import logging
import mimetypes
import os
import re
import ssl
import stat
import string
import sys
Expand All @@ -42,7 +42,7 @@ class _unicode(object):
logger = logging.getLogger('vos')
logger.setLevel(logging.ERROR)
connection_count_logger = logging.getLogger('connections')
connection_count_logger.setLevel(logging.DEBUG)
connection_count_logger.setLevel(logging.ERROR)

if sys.version_info[1] > 6:
connection_count_logger.addHandler(logging.NullHandler())
Expand Down Expand Up @@ -104,9 +104,9 @@ def __init__(self, vospace_certfile=None, vospace_token=None,
"""
self.http_debug = http_debug
self.logger = logging.getLogger('http')
self.logger.setLevel(logging.ERROR)
if sys.version_info[1] > 6:
self.logger.addHandler(logging.NullHandler())
self.logger.setLevel(logging.ERROR)

# # tokens trump certs. We should only ever have token or certfile
## set in order to avoid confusion.
Expand All @@ -120,7 +120,6 @@ def __init__(self, vospace_certfile=None, vospace_token=None,
vospace_certfile = None
self.vospace_certfile = vospace_certfile


def get_connection(self, url):
"""Create an HTTPSConnection object and return. Uses the client
certificate if None given.
Expand Down Expand Up @@ -162,14 +161,19 @@ def get_connection(self, url):
try:
self.logger.debug("Opening connection.")
connection.connect()
break
except httplib.HTTPException as http_exception:
self.logger.critical("%s" % (str(http_exception)))
self.logger.critical("Retrying connection for {0} seconds".format(MAX_RETRY_TIME))
if time.time() - start_time > MAX_RETRY_TIME:
raise http_exception
break
except Exception as e:
if getattr(e, 'errno', errno.EFAULT) == errno.ENOEXEC:
self.logger.error("Failed to connect to VOSpace: No network available?")
else:
self.logger.error(str(e))
break

self.logger.debug("Returning connection object: {0}".format(connection))
return connection


Expand Down Expand Up @@ -1424,7 +1428,6 @@ def getNodeURL(self, uri, method='GET', view=None, limit=0, nextURI=None,
" returns: %s" %
(Client.VOTransfer, response.status))
return self.getNodeURL(uri, method=method, view=view,
full_negotiation=True,
limit=limit, nextURI=nextURI, cutout=cutout)
except Exception as e:
logger.debug(str(e))
Expand All @@ -1434,7 +1437,7 @@ def getNodeURL(self, uri, method='GET', view=None, limit=0, nextURI=None,
logger.debug("Sending short cut url: %s" % (URL))
return URL

# this is a GET that is not a 'data' or 'cutout' view. Add possible additional args to URL.
### this is a GET so we might have to stick some data onto the URL...
fields = {}
if limit is not None:
fields['limit'] = limit
Expand Down Expand Up @@ -1648,7 +1651,8 @@ def open(self, uri, mode=os.O_RDONLY, view=None, head=False, URL=None,
if URL is None:
if target is not None:
logger.debug("%s is a link to %s" % (node.uri, target))
if (re.search("^vos\://cadc\.nrc\.ca[!~]vospace", target) is not None):
if (re.search("^vos\://cadc\.nrc\.ca[!~]vospace", target)
is not None):
# TODO
# the above re.search should use generic VOSpace uri
# search, not CADC specific. i
Expand Down Expand Up @@ -1711,6 +1715,7 @@ def update(self, node, recursive=False):
followRedirect=False)
con.write(str(node))
transURL = con.read()
# logger.debug("Got back %s from $Client.VOProperties " % (con))
# Start the job
con = VOFile(transURL + "/phase", self.conn, method="POST",
followRedirect=False)
Expand All @@ -1722,6 +1727,9 @@ def update(self, node, recursive=False):
con.write(str(node))
con.read()
return 0
#f=self.open(node.uri,mode=os.O_APPEND,size=len(str(node)))
#f.write(str(node))
#f.close()

def mkdir(self, uri):
node = Node(self.fixURI(uri), node_type="vos:ContainerNode")
Expand Down

0 comments on commit 7442d2c

Please sign in to comment.