[Python-checkins] CVS: distutils/distutils util.py,1.34,1.35
Greg Ward
python-dev@python.org
Fri, 16 Jun 2000 19:16:49 -0700
Update of /cvsroot/python/distutils/distutils
In directory slayer.i.sourceforge.net:/tmp/cvs-serv27784
Modified Files:
util.py
Log Message:
Added 'grok_environment_error()' function to deal with the various
forms that IOError and OSError can take (taken from core.py).
Index: util.py
===================================================================
RCS file: /cvsroot/python/distutils/distutils/util.py,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -r1.34 -r1.35
*** util.py 2000/05/31 02:32:10 1.34
--- util.py 2000/06/17 02:16:46 1.35
***************
*** 155,156 ****
--- 155,176 ----
+ def grok_environment_error (exc, prefix="error: "):
+ """Generate a useful error message from an EnvironmentError (IOError or
+ OSError) exception object. Handles Python 1.5.1 and 1.5.2 styles, and
+ does what it can to deal with exception objects that don't have a
+ filename (which happens when the error is due to a two-file operation,
+ such as 'rename()' or 'link()'. Returns the error message as a string
+ prefixed with 'prefix'.
+ """
+ # check for Python 1.5.2-style {IO,OS}Error exception objects
+ if hasattr (exc, 'filename') and hasattr (exc, 'strerror'):
+ if exc.filename:
+ error = prefix + "%s: %s" % (exc.filename, exc.strerror)
+ else:
+ # two-argument functions in posix module don't
+ # include the filename in the exception object!
+ error = prefix + "%s" % exc.strerror
+ else:
+ error = prefix + str(exc[-1])
+
+ return error