initial logging and exception handling changes
This commit is contained in:
@@ -33,12 +33,24 @@ class AgentDomain(object):
|
||||
def __init__(self,uri):
|
||||
"""initialize the agent domain endpoint"""
|
||||
self.uri = uri
|
||||
self.credentials = None
|
||||
self.loginStatus = False
|
||||
log(DEBUG, 'initializing agent domain: %s' %self)
|
||||
|
||||
def login(self, credentials):
|
||||
"""login to the agent domain and return an agent object"""
|
||||
|
||||
log(INFO, 'logging in to %s as %s %s' % (self.uri, credentials.firstname, credentials.lastname))
|
||||
response = self.post_to_loginuri(credentials)
|
||||
|
||||
self.eval_login_response(response)
|
||||
|
||||
return Agent(self)
|
||||
|
||||
def post_to_loginuri(self, credentials):
|
||||
"""post to login_uri and return response"""
|
||||
|
||||
self.credentials = credentials
|
||||
log(INFO, 'logging in to %s as %s %s' % (self.uri, self.credentials.firstname, self.credentials.lastname))
|
||||
|
||||
serializer = ISerialization(credentials) # convert to string via adapter
|
||||
payload = serializer.serialize()
|
||||
@@ -53,23 +65,43 @@ class AgentDomain(object):
|
||||
try:
|
||||
response = restclient.POST(self.uri, payload, headers=headers)
|
||||
except HTTPError, error:
|
||||
if e.code==404:
|
||||
if error.code==404:
|
||||
raise exc.ResourceNotFound(self.uri)
|
||||
else:
|
||||
raise exc.ResourceError(self.uri, error.code, error.msg, error.fp.read(), method="POST")
|
||||
|
||||
seed_cap_url_data = response.body
|
||||
seed_cap_url = llsd.parse(seed_cap_url_data)['agent_seed_capability']
|
||||
self.seed_cap = SeedCapability('seed_cap', seed_cap_url)
|
||||
|
||||
if self.seed_cap is None:
|
||||
raise exc.UserNotAuthorized(self.credentials)
|
||||
else:
|
||||
|
||||
return response
|
||||
|
||||
def eval_login_response(self, response):
|
||||
""" parse the login uri response and return an agent object """
|
||||
|
||||
seed_cap_url_data = self.parse_login_response(response)
|
||||
try:
|
||||
seed_cap_url = seed_cap_url_data['agent_seed_capability']
|
||||
self.seed_cap = SeedCapability('seed_cap', seed_cap_url)
|
||||
self.loginStatus = True
|
||||
log(INFO, 'logged in to %s' % (self.uri))
|
||||
except KeyError:
|
||||
raise exc.UserNotAuthorized(self.credentials)
|
||||
|
||||
return Agent(self)
|
||||
|
||||
def parse_login_response(self, response):
|
||||
""" parse the login uri response and returns deserialized data """
|
||||
|
||||
data = llsd.parse(response.body)
|
||||
|
||||
log(DEBUG, 'deserialized login response body = %s' % (data))
|
||||
try:
|
||||
seed_cap_url = data['agent_seed_capability']
|
||||
self.seed_cap = SeedCapability('seed_cap', seed_cap_url)
|
||||
self.loginStatus = True
|
||||
log(INFO, 'logged in to %s' % (self.uri))
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
return data
|
||||
|
||||
class PlaceAvatar(grok.Adapter):
|
||||
"""handles placing an avatar for an agent object"""
|
||||
grok.implements(IPlaceAvatar)
|
||||
@@ -105,6 +137,9 @@ class PlaceAvatar(grok.Adapter):
|
||||
|
||||
#AND THE REST
|
||||
region.details = result
|
||||
|
||||
log(DEBUG, 'Full rez_avatar/place response is: %s' % (result))
|
||||
|
||||
return avatar
|
||||
|
||||
from interfaces import IEventQueueGet
|
||||
|
||||
@@ -29,21 +29,21 @@ class Capability(object):
|
||||
|
||||
self.name = name
|
||||
self.public_url = public_url
|
||||
log(DEBUG, 'instantiated cap %s' %self)
|
||||
log(INFO, 'instantiated cap %s' %self)
|
||||
|
||||
def GET(self,custom_headers={}):
|
||||
"""call this capability, return the parsed result"""
|
||||
|
||||
log(INFO, '%s: GETing %s' %(self.name, self.public_url))
|
||||
log(DEBUG, '%s: GETing %s' %(self.name, self.public_url))
|
||||
|
||||
try:
|
||||
restclient = getUtility(IRESTClient)
|
||||
response = restclient.GET(self.public_url)
|
||||
except HTTPError, e:
|
||||
if e.code==404:
|
||||
raise exc.ResourceNotFound(self.public_url)
|
||||
else:
|
||||
raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="GET")
|
||||
if e.code==404:
|
||||
raise exc.ResourceNotFound(self.public_url)
|
||||
else:
|
||||
raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="GET")
|
||||
|
||||
# now deserialize the data again, we ask for a utility with the content type
|
||||
# as the name
|
||||
@@ -51,15 +51,21 @@ class Capability(object):
|
||||
content_type = content_type_charset.split(";")[0] # remove the charset part
|
||||
|
||||
deserializer = queryUtility(IDeserialization,name=content_type)
|
||||
|
||||
if deserializer is None:
|
||||
raise exc.DeserializerNotFound(content_type)
|
||||
raise exc.DeserializerNotFound(content_type)
|
||||
|
||||
return deserializer.deserialize_string(response.body)
|
||||
data = deserializer.deserialize_string(response.body)
|
||||
log(DEBUG, 'Get of cap %s response is: %s' % (self.public_url, data))
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def POST(self,payload,custom_headers={}):
|
||||
"""call this capability, return the parsed result"""
|
||||
|
||||
log(DEBUG, 'Sending to cap %s the following payload: %s' %(self.public_url, payload))
|
||||
|
||||
# serialize the data
|
||||
serializer = ISerialization(payload)
|
||||
content_type = serializer.content_type
|
||||
@@ -72,10 +78,10 @@ class Capability(object):
|
||||
restclient = getUtility(IRESTClient)
|
||||
response = restclient.POST(self.public_url, serialized_payload, headers=headers)
|
||||
except HTTPError, e:
|
||||
if e.code==404:
|
||||
raise exc.ResourceNotFound(self.public_url)
|
||||
else:
|
||||
raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="POST")
|
||||
if e.code==404:
|
||||
raise exc.ResourceNotFound(self.public_url)
|
||||
else:
|
||||
raise exc.ResourceError(self.public_url, e.code, e.msg, e.fp.read(), method="POST")
|
||||
|
||||
# now deserialize the data again, we ask for a utility with the content type
|
||||
# as the name
|
||||
@@ -83,9 +89,14 @@ class Capability(object):
|
||||
content_type = content_type_charset.split(";")[0] # remove the charset part
|
||||
|
||||
deserializer = queryUtility(IDeserialization,name=content_type)
|
||||
|
||||
if deserializer is None:
|
||||
raise exc.DeserializerNotFound(content_type)
|
||||
return deserializer.deserialize_string(response.body)
|
||||
raise exc.DeserializerNotFound(content_type)
|
||||
|
||||
data = deserializer.deserialize_string(response.body)
|
||||
log(DEBUG, 'Post to cap %s response is: %s' % (self.public_url, data))
|
||||
|
||||
return data
|
||||
|
||||
def __repr__(self):
|
||||
return "<Capability '%s' for %s>" %(self.name, self.public_url)
|
||||
|
||||
@@ -28,7 +28,7 @@ def login():
|
||||
# would be nice to be able to kill threads with Ctrl-C now wouldnt it?
|
||||
# i have yet to see this actually kill a thread tho....
|
||||
|
||||
signal.signal(signal.SIGINT, sigint_handler)
|
||||
#signal.signal(signal.SIGINT, sigint_handler)
|
||||
|
||||
registration.init()
|
||||
parser = OptionParser()
|
||||
@@ -106,6 +106,8 @@ class eventQueueGet(Thread):
|
||||
result = self.eqg()
|
||||
self.logger.debug("it returned: %s", result)
|
||||
|
||||
|
||||
|
||||
def sigint_handler(signal, frame):
|
||||
global RUNNING
|
||||
RUNNING = False
|
||||
|
||||
@@ -77,7 +77,7 @@ class EventQueueGet(grok.Adapter):
|
||||
# let's retrieve the cap we need
|
||||
self.seed_cap = self.context.seed_cap # ISeedCapability
|
||||
|
||||
log(DEBUG, 'intitializing region domain event queue via the seed cap: %s' % (self.seed_cap_url))
|
||||
log(DEBUG, 'intitializing region domain event queue via the seed cap: %s' % (self.seed_cap))
|
||||
|
||||
self.cap = self.seed_cap.get(['EventQueueGet'])['EventQueueGet']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user