7027131 userland-fetch should be more verbose when printing IOError exception
authorVladimir Marek <Vladimir.Marek@oracle.com>
Wed, 16 Mar 2011 12:03:52 -0700
changeset 136 6a7dd3a5aaf9
parent 135 5c6feb0253fa
child 137 6fb20db3eee4
7027131 userland-fetch should be more verbose when printing IOError exception
tools/userland-fetch
--- a/tools/userland-fetch	Wed Mar 16 07:42:49 2011 -0700
+++ b/tools/userland-fetch	Wed Mar 16 12:03:52 2011 -0700
@@ -34,6 +34,15 @@
 from urllib import splittype, urlopen
 import hashlib
 
+def printIOError(e, txt):
+	""" Function to decode and print IOError type exception """
+	print "I/O Error: " + txt + ": "
+	try:
+		(code, message) = e
+		print str(message) + " (" + str(code) + ")"
+	except:
+		print str(e)
+	
 def validate(file, hash):
 	algorithm, hashvalue = hash.split(':')
 	try:
@@ -52,7 +61,8 @@
 def validate_container(filename, hash):
 	try:
 		file = open(filename, 'r')
-	except IOError:
+	except IOError as e:
+		printIOError(e, "Can't open file " + filename)
 		return False
 	return validate(file, hash)
 
@@ -72,7 +82,8 @@
 			file = gzip.GzipFile(filename, 'r')
 		else:
 			return False
-	except IOError:
+	except IOError as e:
+		printIOError(e, "Can't open archive " + filename)
 		return False
 	return validate(file, hash)
 
@@ -82,7 +93,8 @@
 
 	try:
 		src = urlopen(url)
-	except IOError:
+	except IOError as e:
+		printIOError(e, "Can't open url " + url)
 		return None
 
 	if filename == None:
@@ -90,7 +102,8 @@
 
 	try:
 		dst = open(filename, 'wb');
-	except IOError:
+	except IOError as e:
+		printIOError(e, "Can't open file " + filename + " for writing")
 		src.close()
 		return None