diff options
author | William Deegan <bill@baddogconsulting.com> | 2017-05-16 22:55:14 (GMT) |
---|---|---|
committer | William Deegan <bill@baddogconsulting.com> | 2017-05-16 22:55:14 (GMT) |
commit | ad585a82b9ae5108914efef69f172d76061e81c5 (patch) | |
tree | b2fe801e588e9a8d623663ac1b2559727fe43e42 /src/engine/SCons | |
parent | 1486cb6e1c77cf36049d10717099af7b27dd4934 (diff) | |
download | SCons-ad585a82b9ae5108914efef69f172d76061e81c5.zip SCons-ad585a82b9ae5108914efef69f172d76061e81c5.tar.gz SCons-ad585a82b9ae5108914efef69f172d76061e81c5.tar.bz2 |
PY2/3 stub shutil.SameFileError for py2. with PY3 there's now a specific exception for copying a file onto itself. Info about the exception is held in the exception object differently than IOError,etc
Diffstat (limited to 'src/engine/SCons')
-rw-r--r-- | src/engine/SCons/Errors.py | 25 | ||||
-rw-r--r-- | src/engine/SCons/compat/__init__.py | 9 |
2 files changed, 32 insertions, 2 deletions
diff --git a/src/engine/SCons/Errors.py b/src/engine/SCons/Errors.py index 4199ab7..1df8cb9 100644 --- a/src/engine/SCons/Errors.py +++ b/src/engine/SCons/Errors.py @@ -30,6 +30,7 @@ and user errors in SCons. __revision__ = "__FILE__ __REVISION__ __DATE__ __DEVELOPER__" +import shutil import SCons.Util @@ -87,12 +88,14 @@ class BuildError(Exception): is not due to the an action failure) """ - def __init__(self, + def __init__(self, node=None, errstr="Unknown error", status=2, exitstatus=2, filename=None, executor=None, action=None, command=None, exc_info=(None, None, None)): # py3: errstr should be string and not bytes. + # import pdb; pdb.set_trace() + self.errstr = SCons.Util.to_str(errstr) self.status = status self.exitstatus = exitstatus @@ -104,7 +107,7 @@ class BuildError(Exception): self.action = action self.command = command - Exception.__init__(self, node, errstr, status, exitstatus, filename, + Exception.__init__(self, node, errstr, status, exitstatus, filename, executor, action, command, exc_info) def __str__(self): @@ -143,6 +146,9 @@ def convert_to_BuildError(status, exc_info=None): The buildError.status we set here will normally be used as the exit status of the "scons" process. """ + + # import pdb; pdb.set_trace() + if not exc_info and isinstance(status, Exception): exc_info = (status.__class__, status, None) @@ -164,6 +170,21 @@ def convert_to_BuildError(status, exc_info=None): status=2, exitstatus=2, exc_info=exc_info) + elif isinstance(status, shutil.SameFileError): + # PY3 has a exception for when copying file to itself + # It's object provides info differently than below + try: + filename = status.filename + except AttributeError: + filename = None + + buildError = BuildError( + errstr=status.args[0], + status=status.errno, + exitstatus=2, + filename=filename, + exc_info=exc_info) + elif isinstance(status, (EnvironmentError, OSError, IOError)): # If an IOError/OSError happens, raise a BuildError. # Report the name of the file or directory that caused the diff --git a/src/engine/SCons/compat/__init__.py b/src/engine/SCons/compat/__init__.py index 477b67c..59a1a94 100644 --- a/src/engine/SCons/compat/__init__.py +++ b/src/engine/SCons/compat/__init__.py @@ -146,6 +146,15 @@ except AttributeError: del _UserString +import shutil +try: + shutil.SameFileError +except AttributeError: + class SameFileError(Exception): + pass + + shutil.SameFileError = SameFileError + def with_metaclass(meta, *bases): """ Function from jinja2/_compat.py. License: BSD. |