diff options
author | Greg Ward <gward@python.net> | 2000-06-17 02:16:46 (GMT) |
---|---|---|
committer | Greg Ward <gward@python.net> | 2000-06-17 02:16:46 (GMT) |
commit | e905513be0718c5a8edafe70efc0fe0d4f290573 (patch) | |
tree | ece70bdbe74ed1dabaeafe9a60cadf347de3fc3b /Lib/distutils/util.py | |
parent | 039accfb2caafdaa6d792f09b217ff0f5935df42 (diff) | |
download | cpython-e905513be0718c5a8edafe70efc0fe0d4f290573.zip cpython-e905513be0718c5a8edafe70efc0fe0d4f290573.tar.gz cpython-e905513be0718c5a8edafe70efc0fe0d4f290573.tar.bz2 |
Added 'grok_environment_error()' function to deal with the various
forms that IOError and OSError can take (taken from core.py).
Diffstat (limited to 'Lib/distutils/util.py')
-rw-r--r-- | Lib/distutils/util.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py index 5754638..279f246 100644 --- a/Lib/distutils/util.py +++ b/Lib/distutils/util.py @@ -154,3 +154,23 @@ def subst_vars (str, local_vars): # subst_vars () +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 |