Replaced occurances of |str(e)| with |"%s" % e|.

Except in bin/glance, where |unicode(e).split('\n')| makes more sense than |("%s" % e).split('\n')|
This commit is contained in:
Justin Shepherd 2011-08-02 17:43:16 +00:00 committed by Tarmac
commit 22305dc6ce
7 changed files with 16 additions and 16 deletions

View File

@ -58,7 +58,7 @@ def catch_error(action):
return SUCCESS if ret is None else ret
except Exception, e:
print "Failed to %s. Got error:" % action
pieces = str(e).split('\n')
pieces = unicode(e).split('\n')
for piece in pieces:
print piece
return FAILURE
@ -231,13 +231,13 @@ EXAMPLES
print ("Failed to connect to the Glance API server "
"%(host)s:%(port)d. Is the server running?" % locals())
if options.verbose:
pieces = str(e).split('\n')
pieces = unicode(e).split('\n')
for piece in pieces:
print piece
return FAILURE
except Exception, e:
print "Failed to add image. Got error:"
pieces = str(e).split('\n')
pieces = unicode(e).split('\n')
for piece in pieces:
print piece
print ("Note: Your image metadata may still be in the registry, "
@ -326,7 +326,7 @@ to spell field names correctly. :)"""
return FAILURE
except Exception, e:
print "Failed to update image. Got error:"
pieces = str(e).split('\n')
pieces = unicode(e).split('\n')
for piece in pieces:
print piece
return FAILURE
@ -389,7 +389,7 @@ Shows image metadata for an image in Glance"""
return FAILURE
except Exception, e:
print "Failed to show image. Got error:"
pieces = str(e).split('\n')
pieces = unicode(e).split('\n')
for piece in pieces:
print piece
return FAILURE
@ -454,7 +454,7 @@ a Glance server knows about"""
return SUCCESS
except Exception, e:
print "Failed to show details. Got error:"
pieces = str(e).split('\n')
pieces = unicode(e).split('\n')
for piece in pieces:
print piece
return FAILURE

View File

@ -125,7 +125,7 @@ def do_start(server, options, args):
os.execlp('%s' % server, server, ini_file)
except OSError, e:
sys.exit('unable to launch %s. Got error: %s'
% (server, str(e)))
% (server, "%s" % e))
sys.exit(0)
else:
write_pid_file(pid_file, pid)

View File

@ -122,7 +122,7 @@ def main():
try:
new_meta = client.add_image(meta, f)
except Exception, e:
print "Failed to add new image. Got error: ", str(e)
print "Failed to add new image. Got error: %s" % e
return 1
print 'Stored image. Got identifier: %s' % pprint.pformat(new_meta)

View File

@ -80,7 +80,7 @@ class Controller(api.BaseController):
try:
self.cache.queue_prefetch(image_meta)
except exception.Invalid, e:
raise webob.exc.HTTPBadRequest(explanation=str(e))
raise webob.exc.HTTPBadRequest(explanation="%s" % e)
class CachedImageDeserializer(wsgi.JSONRequestDeserializer):

View File

@ -107,7 +107,7 @@ class Controller(api.BaseController):
images = registry.get_images_list(self.options, req.context,
**params)
except exception.Invalid, e:
raise HTTPBadRequest(explanation=str(e))
raise HTTPBadRequest(explanation="%s" % e)
return dict(images=images)
@ -138,7 +138,7 @@ class Controller(api.BaseController):
images = registry.get_images_detail(self.options, req.context,
**params)
except exception.Invalid, e:
raise HTTPBadRequest(explanation=str(e))
raise HTTPBadRequest(explanation="%s" % e)
return dict(images=images)
def _get_query_params(self, req):
@ -365,20 +365,20 @@ class Controller(api.BaseController):
return location
except exception.Duplicate, e:
msg = ("Attempt to upload duplicate image: %s") % str(e)
msg = ("Attempt to upload duplicate image: %s") % e
logger.error(msg)
self._safe_kill(req, image_id)
raise HTTPConflict(msg, request=req)
except exception.NotAuthorized, e:
msg = ("Unauthorized upload attempt: %s") % str(e)
msg = ("Unauthorized upload attempt: %s") % e
logger.error(msg)
self._safe_kill(req, image_id)
raise HTTPForbidden(msg, request=req,
content_type='text/plain')
except Exception, e:
msg = ("Error uploading image: %s") % str(e)
msg = ("Error uploading image: %s") % e
logger.error(msg)
self._safe_kill(req, image_id)
raise HTTPBadRequest(msg, request=req)

View File

@ -115,7 +115,7 @@ def wrap_exception(f):
#exc_type, exc_value, exc_traceback = sys.exc_info()
logging.exception('Uncaught exception')
#logging.error(traceback.extract_stack(exc_traceback))
raise Error(str(e))
raise Error("%s" % e)
raise
_wrap.func_name = f.func_name
return _wrap

View File

@ -202,7 +202,7 @@ class ImageCache(object):
def rollback(e):
set_xattr('image_name', image_meta['name'])
set_xattr('error', str(e))
set_xattr('error', "%s" % e)
invalid_path = self.invalid_path_for_image(image_id)
logger.debug("fetch errored, rolling back by moving "