Skip to content

Commit

Permalink
Merge pull request #2 from BigRoy/master
Browse files Browse the repository at this point in the history
Fix #1: Backwards compatibility to Python <3.3
Looks good, merging. Thanks.
  • Loading branch information
antirotor authored May 28, 2019
2 parents 22d50a4 + 0d679af commit 6c2ab5a
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions speedcopy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,22 @@ def copyfile(src, dst, follow_symlinks=True):
as robocopy is probably faster, but robocopy doesn't support renaming
destination file when copying just one file :( Shame on you Microsoft.
"""
from subprocess import call, DEVNULL
from subprocess import call

try:
# Python 3.3+
from subprocess import DEVNULL
except ImportError:
# Backwards compatibility
DEVNULL = open(os.devnull, 'w')

# from pathlib import Path, PureWindowsPath
if shutil._samefile(src, dst):
raise shutil.SameFileError(

# Get shutil.SameFileError if available (Python 3.4+)
# else fall back to original behavior using shutil.Error
SameFileError = getattr(shutil, "SameFileError", shutil.Error)
raise SameFileError(
"{!r} and {!r} are the same file".format(src, dst))

for fn in [src, dst]:
Expand Down

0 comments on commit 6c2ab5a

Please sign in to comment.