diff options
Diffstat (limited to 'ranger/ext/shutil_generatorized.py')
-rw-r--r-- | ranger/ext/shutil_generatorized.py | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/ranger/ext/shutil_generatorized.py b/ranger/ext/shutil_generatorized.py index 7958b048..1bf95842 100644 --- a/ranger/ext/shutil_generatorized.py +++ b/ranger/ext/shutil_generatorized.py @@ -16,9 +16,11 @@ __all__ = ["copyfileobj", "copyfile", "copystat", "copy2", "BLOCK_SIZE", APPENDIX = '_' BLOCK_SIZE = 16 * 1024 + class Error(EnvironmentError): pass + class SpecialFileError(EnvironmentError): """Raised when trying to do a kind of operation (e.g. copying) which is not supported on a special file (e.g. a named pipe)""" @@ -28,6 +30,7 @@ try: except NameError: WindowsError = None + def copyfileobj(fsrc, fdst, length=BLOCK_SIZE): """copy data from file-like object fsrc to file-like object fdst""" done = 0 @@ -39,6 +42,7 @@ def copyfileobj(fsrc, fdst, length=BLOCK_SIZE): done += len(buf) yield done + def _samefile(src, dst): # Macintosh, Unix. if hasattr(os.path, 'samefile'): @@ -51,6 +55,7 @@ def _samefile(src, dst): return (os.path.normcase(abspath(src)) == os.path.normcase(abspath(dst))) + def copyfile(src, dst): """Copy data from src to dst""" if _samefile(src, dst): @@ -79,6 +84,7 @@ def copyfile(src, dst): if fsrc: fsrc.close() + def copystat(src, dst): """Copy all stat info (mode bits, atime, mtime, flags) from src to dst""" st = os.lstat(src) @@ -93,6 +99,7 @@ def copystat(src, dst): try: os.chflags(dst, st.st_flags) except: pass + def copy2(src, dst, overwrite=False, symlinks=False): """Copy data and all stat info ("cp -p src dst"). @@ -113,6 +120,7 @@ def copy2(src, dst, overwrite=False, symlinks=False): yield done copystat(src, dst) + def get_safe_path(dst): if not os.path.exists(dst): return dst @@ -128,6 +136,7 @@ def get_safe_path(dst): return test_dst + def copytree(src, dst, symlinks=False, ignore=None, overwrite=False): """Recursively copy a directory tree using copy2(). @@ -210,6 +219,7 @@ def copytree(src, dst, symlinks=False, ignore=None, overwrite=False): if errors: raise Error(errors) + def rmtree(path, ignore_errors=False, onerror=None): """Recursively delete a directory tree. @@ -264,6 +274,7 @@ def _basename(path): # Thus we always get the last component of the path, even for directories. return os.path.basename(path.rstrip(os.path.sep)) + def move(src, dst, overwrite=False): """Recursively move a file or directory to another location. This is similar to the Unix "mv" command. @@ -298,6 +309,7 @@ def move(src, dst, overwrite=False): yield done os.unlink(src) + def _destinsrc(src, dst): src = abspath(src) dst = abspath(dst) |