当前位置: 首页>>代码示例>>Python>>正文


Python shutil._samefile函数代码示例

本文整理汇总了Python中shutil._samefile函数的典型用法代码示例。如果您正苦于以下问题:Python _samefile函数的具体用法?Python _samefile怎么用?Python _samefile使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了_samefile函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cp

	def cp( self , dst , basename = None , overwrite = False ):

		src = self
		dst = __mod__.Shell( dst , delegated = True )

		if basename == None:
			dst = dst( self.BASENAME )
		else:
			dst = dst( basename )

		if shutil._samefile(src, dst):
			raise shutil.Error( "`%s` and `%s` are the same file" % (src, tmp_dst) )		

		#print 3334444 , 'shell.cp1' , dst 
		#print 3334444 , 'shell.cp2' , dst.PARENT

		dst.PARENT.MKDIR

		#Optimization
		buffer_size = min( 10485760 , os.path.getsize(src) ) or 1024 

		#No copia si son iguales
		if not overwrite and dst.ISFILE:
			if self.cmp( dst ):
				print 'Same file, no copy %s' % dst
				return dst 

		with open(src, 'rb') as fsrc:
			with open(dst, 'wb') as fdst:
				shutil.copyfileobj( fsrc, fdst, buffer_size )
				shutil.copystat( src, dst )

		return dst
开发者ID:javi2d,项目名称:medula,代码行数:33,代码来源:shell.py

示例2: copy

  def copy(self):
    print("Checking paths...", end="", flush=True)
    destination_path = self.network_path + self.relative_path
    files_are_the_same = shutil._samefile(self.absolute_path, destination_path)
    print(" DONE!")

    if files_are_the_same:
      print("Files are the same. Skipping copy!")
      return
    else:
      print("Copying '" + self.absolute_path + "' to '" + destination_path + "'...", end="", flush=True)

    success = False
    try:
      shutil.copy(self.absolute_path, destination_path)
      success = True
    except shutil.Error as e:
      print(" FAILED!\n\tError: %s" % e)
    except OSError as e:
      print(" FAILED!\n\tOS Error: {m} ({n}).".format(m=e.strerror, n=e.errno))

    if (not success):
      print("\nBuild aborted!")
      sys.exit(0)

    print(" DONE!")
开发者ID:taschetto,项目名称:sublimeSettings,代码行数:26,代码来源:Builder.py

示例3: copyFile

def copyFile(sourcePath, destinationPath, zstreamWrapperListener = None):
    if not os.path.isfile(sourcePath):
        return    
    if not zstreamWrapperListener:
        shutil.copy2(sourcePath, destinationPath)
    else:
        #
        # equivalent code of shutil.copy2() except uses ZStreamWrapper
        #        
        if os.path.isdir(destinationPath):
            destinationPath = os.path.join(destinationPath, os.path.basename(sourcePath))
                
        if shutil._samefile(sourcePath, destinationPath):
            raise Error, u"`%s` and `%s` are the same file" % (sourcePath, destinationPath) #$NON-NLS-1$
        srcwrapper = None
        fdst = None
        try:
            fsrc = open(sourcePath, u'rb') #$NON-NLS-1$
            srcwrapper = ZStreamWrapper(fsrc, zstreamWrapperListener)
            fdst = open(destinationPath, u'wb') #$NON-NLS-1$
            shutil.copyfileobj(srcwrapper, fdst)
        finally:
            if fdst:
                fdst.close()
            if srcwrapper:
                srcwrapper.close()
        shutil.copystat(sourcePath, destinationPath)
开发者ID:Tidosho,项目名称:zoundryraven,代码行数:27,代码来源:fileutil.py

示例4: shutil_copyfile

def shutil_copyfile(src, dst):
    """Copy data from src to dst"""
    if shutil._samefile(src, dst):
        raise shutil.Error("`%s` and `%s` are the same file" % (src, dst))
    elif not os.path.exists(src) or os.path.isdir(src):
        return

    for fn in [src, dst]:
        try:
            st = os.stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            # XXX What about other special files? (sockets, devices...)
            if stat.S_ISFIFO(st.st_mode):
                try:
                    raise shutil.SpecialFileError("`%s` is a named pipe" % fn)
                except NameError:
                    raise shutil.Error("`%s` is a named pipe" % fn)

    BUFFER_SIZE = 128*1024
    try:
        with open(src, "rb") as fin, open(dst, "wb") as fout:
            for x in iter(lambda: fin.read(BUFFER_SIZE), ""):
                fout.write(x)
    except Exception as e:
        raise
开发者ID:fabiankaeser,项目名称:SickRage,代码行数:28,代码来源:patches.py

示例5: move

 def move(self, library, copy=False):
     """Move the item to its designated location within the library
     directory (provided by destination()). Subdirectories are
     created as needed. If the operation succeeds, the item's path
     field is updated to reflect the new location.
     
     If copy is True, moving the file is copied rather than moved.
     
     Passes on appropriate exceptions if directories cannot be created
     or moving/copying fails.
     
     Note that one should almost certainly call store() and
     library.save() after this method in order to keep on-disk data
     consistent.
     """
     dest = library.destination(self)
     
     # Create necessary ancestry for the move.
     _mkdirall(dest)
     
     if not shutil._samefile(_syspath(self.path), _syspath(dest)):
         if copy:
             # copyfile rather than copy will not copy permissions
             # bits, thus possibly making the copy writable even when
             # the original is read-only.
             shutil.copyfile(_syspath(self.path), _syspath(dest))
         else:
             shutil.move(_syspath(self.path), _syspath(dest))
         
     # Either copying or moving succeeded, so update the stored path.
     self.path = dest
开发者ID:billthornton,项目名称:beets,代码行数:31,代码来源:library.py

示例6: copyFile

def copyFile(FileSource, Destination, BufferSize=1024 * 1024 * 10, PerserveFileDate=True):
    '''
    Copies a file to a new location. Much faster performance than Apache Commons due to use of larger buffer
    @param FileSource:          Source File
    @param Destination:         Destination File (not file path)
    @param BufferSize:          Buffer size to use during copy
    @param PerserveFileDate:    Preserve the original file date
    '''

    
    #    Optimize the buffer for small files
    BufferSize = min(BufferSize, os.path.getsize(FileSource))
    if(BufferSize == 0):
        BufferSize = 1024
    
    if shutil._samefile(FileSource, Destination):
        LogBrowser("`{0}` and `{1}` are the same file".format(FileSource, Destination), "ERROR")
        raise shutil.Error("`{0}` and `{1}` are the same file".format(FileSource, Destination))
    for FileName in [FileSource, Destination]:
        try:
            st = os.stat(FileName)
        except OSError:
            #   File most likely does not exist
            pass
        else:
            #   XXX What about other special files? (sockets, devices...)
            if shutil.stat.S_ISFIFO(st.st_mode):
                LogBrowser("`{0}` is a named pipe".format(FileName), "ERROR")
                raise shutil.SpecialFileError("`{0}` is a named pipe".format(FileName))
    with open(FileSource, 'rb') as fFileSource:
        with open(Destination, 'wb') as fDestination:
            shutil.copyfileobj(fFileSource, fDestination, BufferSize)
    
    if(PerserveFileDate):
        shutil.copystat(FileSource, Destination)
开发者ID:TheBlueFireFox,项目名称:RenameAnimeScript,代码行数:35,代码来源:Rename.py

示例7: copyfile

    def copyfile(src, dst, follow_symlinks=True):
        """Copy data from src to dst.

    If follow_symlinks is not set and src is a symbolic link, a new
    symlink will be created instead of copying the file it points to.

    """
        if shutil._samefile(src, dst):
            raise shutil.SameFileError("{!r} and {!r} are the same file".format(src, dst))

        for fn in [src, dst]:
            try:
                st = os.stat(fn)
            except OSError:
                # File most likely does not exist
                pass
            else:
                # XXX What about other special files? (sockets, devices...)
                if stat.S_ISFIFO(st.st_mode):
                    raise shutil.SpecialFileError("`%s` is a named pipe" % fn)

        if not follow_symlinks and os.path.islink(src):
            os.symlink(os.readlink(src), dst)
        else:
            with open(src, "rb") as fsrc, open(dst, "wb") as fdst:
                # Try to use sendfile if available for performance
                if not _copyfile_sendfile(fsrc, fdst):
                    # sendfile is not available or failed, fallback to copyfileobj
                    shutil.copyfileobj(fsrc, fdst)
        return dst
开发者ID:desbma,项目名称:pyfastcopy,代码行数:30,代码来源:__init__.py

示例8: copyfile

def copyfile(src, dst, follow_symlinks=True):
    """Copy data from src to dst.

    If follow_symlinks is not set and src is a symbolic link, a new
    symlink will be created instead of copying the file it points to.

    NOTE: this is a copy of shutil.copyfile from python 3.5, modified to be compatible
    with python2.7, with the exception of the buffer size
    used in copying the file contents.
    """
    # noinspection PyUnresolvedReferences,PyProtectedMember
    if shutil._samefile(src, dst):
        raise SameFileError("{!r} and {!r} are the same file".format(src, dst))

    for fn in [src, dst]:
        try:
            st = os.stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            # XXX What about other special files? (sockets, devices...)
            if stat.S_ISFIFO(st.st_mode):
                raise shutil.SpecialFileError("`%s` is a named pipe" % fn)

    if not follow_symlinks and os.path.islink(src):
        os.symlink(os.readlink(src), dst)
    else:
        with open(src, 'rb') as fsrc:
            with open(dst, 'wb') as fdst:
                shutil.copyfileobj(fsrc, fdst, length=COPY_BUFFSIZE)
    return dst
开发者ID:cfe-lab,项目名称:Kive,代码行数:32,代码来源:file_access_utils.py

示例9: copy_file

def copy_file(src, dst, mk_dst=True):
    # mk_dst: make directory if doesn't exists
    if shutil._samefile(src, dst):
        msg = "{!r} and {!r} are the same file".format(src, dst)
        raise shutil.SameFileError(msg)
    else:
        if mk_dst:
            paths.mkdir(os.path.dirname(dst))
        source_size = os.stat(src).st_size
        with open(src, 'rb') as fsrc:
            with open(dst, 'wb') as fdst:
                copyfileobj(fsrc, fdst, source_size)

    return dst
开发者ID:shahinism,项目名称:cinemabit,代码行数:14,代码来源:files.py

示例10: shutil_move

def shutil_move(src, dst):
    """Recursively move a file or directory to another location. This is
    similar to the Unix "mv" command. Return the file or directory's
    destination.

    If the destination is a directory or a symlink to a directory, the source
    is moved inside the directory. The destination path must not already
    exist.

    If the destination already exists but is not a directory, it may be
    overwritten depending on os.rename() semantics.

    If the destination is on our current filesystem, then rename() is used.
    Otherwise, src is copied to the destination and then removed. Symlinks are
    recreated under the new name if os.rename() fails because of cross
    filesystem renames.

    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    """
    real_dst = dst
    if _os.path.isdir(dst):
        if shutil._samefile(src, dst):
            # We might be on a case insensitive filesystem,
            # perform the rename anyway.
            _os.rename(src, dst)
            return

        real_dst = _os.path.join(dst, shutil._basename(src))
        if _os.path.exists(real_dst):
            raise shutil.Error("Destination path '%s' already exists" % real_dst)
    try:
        _os.rename(src, real_dst)
    except OSError:
        if _os.path.islink(src):
            linkto = _os.readlink(src)
            _os.symlink(linkto, real_dst)
            _os.unlink(src)
        elif _os.path.isdir(src):
            if shutil._destinsrc(src, dst):
                raise shutil.Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
            shutil.copytree(src, real_dst, symlinks=True)
            shutil.rmtree(src)
        else:
            shutil.copy2(src, real_dst)
            _os.unlink(src)
    return real_dst
开发者ID:joshuasb,项目名称:knossos,代码行数:48,代码来源:py2_compat.py

示例11: CopyFile2

def CopyFile2(src, dst, buffer_size=10485760, perserveFileDate=True):
    '''
    Copies a file to a new location. Much faster performance than Apache Commons due to use of larger buffer
    @param src:    Source File
    @param dst:    Destination File (not file path)
    @param buffer_size:    Buffer size to use during copy
    @param perserveFileDate:    Preserve the original file date
    '''
    try:
        #    Check to make sure destination directory exists. If it doesn't create the directory
        dstParent, dstFileName = os.path.split(dst)
        if(not(os.path.exists(dstParent))):
            os.makedirs(dstParent)

        #    Optimize the buffer for small files
        buffer_size = min(buffer_size, os.path.getsize(src))
        if(buffer_size == 0):
            buffer_size = 1024

        if shutil._samefile(src, dst):
            raise shutil.Error("`%s` and `%s` are the same file" % (src, dst))
        for fn in [src, dst]:
            try:
                st = os.stat(fn)
            except OSError:
                # File most likely does not exist
                pass
            else:
                # XXX What about other special files? (sockets, devices...)
                if shutil.stat.S_ISFIFO(st.st_mode):
                    raise shutil.SpecialFileError("`%s` is a named pipe" % fn)
        with open(src, 'rb') as fsrc:
            with open(dst, 'wb') as fdst:
                shutil.copyfileobj(fsrc, fdst, buffer_size)

        if(perserveFileDate):
            CopyStat(src, dst)

        return True

    except Exception, e:
        print "Error:", e
        if os.name == 'nt':
            try:
                WinCopy(src, dst)
                return True
            except Exception, e1:
                print "WinCopy Error:", e1
开发者ID:IqbalHassan,项目名称:Framework_0.1,代码行数:48,代码来源:FileUtilities.py

示例12: copyfile

def copyfile(src, dst):
    """Copy data from src to dst"""
    if _samefile(src, dst):
        raise Error("`%s` and `%s` are the same file" % (src, dst))

    for fn in [src, dst]:
        try:
            st = os.stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            # XXX What about other special files? (sockets, devices...)
            if stat.S_ISFIFO(st.st_mode):
                raise SpecialFileError("`%s` is a named pipe" % fn)

    with open(src, 'rb') as fsrc:
        with open(dst, 'wb') as fdst:
            copyfileobj(fsrc, fdst)
开发者ID:beyondai,项目名称:cms,代码行数:19,代码来源:GeventUtils.py

示例13: copyfile_custom

def copyfile_custom(src, dst):
    """Copy data from src to dst"""
    if _samefile(src, dst):
        raise Error("`%s` and `%s` are the same file" % (src, dst))

    for fn in [src, dst]:
        try:
            st = os.stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            # XXX What about other special files? (sockets, devices...)
            if stat.S_ISFIFO(st.st_mode):
                try:
                    raise SpecialFileError("`%s` is a named pipe" % fn)
                except NameError:
                    raise Error("`%s` is a named pipe" % fn)

    try:
        # Windows
        O_BINARY = os.O_BINARY
    except:
        O_BINARY = 0

    READ_FLAGS = os.O_RDONLY | O_BINARY
    WRITE_FLAGS = os.O_WRONLY | os.O_CREAT | os.O_TRUNC | O_BINARY
    BUFFER_SIZE = 128*1024

    try:
        fin = os.open(src, READ_FLAGS)
        fout = os.open(dst, WRITE_FLAGS)
        for x in iter(lambda: os.read(fin, BUFFER_SIZE), ""):
            os.write(fout, x)
    except Exception as e:
        raise e
    finally:
        try:
            os.close(fin)
            os.close(fout)
        except:
            pass
开发者ID:Eiber,项目名称:OLD-Sickrage,代码行数:42,代码来源:__init__.py

示例14: move

def move(src, dst):
    """Recursively move a file or directory to another location. This is
    similar to the Unix "mv" command.

    If the destination is a directory or a symlink to a directory, the source
    is moved inside the directory. The destination path must not already
    exist.

    If the destination already exists but is not a directory, it may be
    overwritten depending on os.rename() semantics.

    If the destination is on our current filesystem, then rename() is used.
    Otherwise, src is copied to the destination and then removed.
    A lot more could be done here...  A look at a mv.c shows a lot of
    the issues this implementation glosses over.

    """
    real_dst = dst
    if os.path.isdir(dst):
        if _samefile(src, dst):
            # We might be on a case insensitive filesystem,
            # perform the rename anyway.
            os.rename(src, dst)
            return

        real_dst = os.path.join(dst, _basename(src))
        if os.path.exists(real_dst):
            raise Error("Destination path '%s' already exists" % real_dst)
    try:
        os.rename(src, real_dst)
    except OSError:
        if os.path.isdir(src):
            if _destinsrc(src, dst):
                msg = "Cannot move a directory '%s' into itself '%s'." % (src,
                                                                          dst)
                raise Error(msg)
            copytree(src, real_dst, symlinks=True)
            rmtree(src)
        else:
            copy(src, real_dst)
            os.unlink(src)
开发者ID:Outernet-Project,项目名称:fsal,代码行数:41,代码来源:asyncfs.py

示例15: copyfile_custom

def copyfile_custom(src, dst):
    """Copy data from src to dst."""
    def special_file(fn):
        try:
            st = os.stat(fn)
        except OSError:
            # File most likely does not exist
            pass
        else:
            if stat.S_ISFIFO(st.st_mode):
                raise SpecialFileError("{!r} is a named pipe".format(fn))

    if _samefile(src, dst):
        raise SameFileError("{!r} and {!r} are the same file".format(src, dst))

    special_file(src)
    special_file(dst)

    with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst:
        while True:
            buf = fsrc.read(BUFFER_SIZE)
            if not buf:
                break
            fdst.write(buf)
开发者ID:pymedusa,项目名称:SickRage,代码行数:24,代码来源:__init__.py


注:本文中的shutil._samefile函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。