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


Python shutil.SpecialFileError方法代码示例

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


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

示例1: _copy2_ignoring_special_files

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def _copy2_ignoring_special_files(src, dest):
    # type: (str, str) -> None
    """Copying special files is not supported, but as a convenience to users
    we skip errors copying them. This supports tools that may create e.g.
    socket files in the project source directory.
    """
    try:
        copy2_fixed(src, dest)
    except shutil.SpecialFileError as e:
        # SpecialFileError may be raised due to either the source or
        # destination. If the destination was the cause then we would actually
        # care, but since the destination directory is deleted prior to
        # copy we ignore all of them assuming it is caused by the source.
        logger.warning(
            "Ignoring special file error '%s' encountered copying %s to %s.",
            str(e),
            path_to_display(src),
            path_to_display(dest),
        ) 
开发者ID:pantsbuild,项目名称:pex,代码行数:21,代码来源:prepare.py

示例2: copy2_fixed

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def copy2_fixed(src, dest):
    # type: (str, str) -> None
    """Wrap shutil.copy2() but map errors copying socket files to
    SpecialFileError as expected.

    See also https://bugs.python.org/issue37700.
    """
    try:
        shutil.copy2(src, dest)
    except (OSError, IOError):
        for f in [src, dest]:
            try:
                is_socket_file = is_socket(f)
            except OSError:
                # An error has already occurred. Another error here is not
                # a problem and we can ignore it.
                pass
            else:
                if is_socket_file:
                    raise shutil.SpecialFileError("`%s` is a socket" % f)

        raise 
开发者ID:pantsbuild,项目名称:pex,代码行数:24,代码来源:filesystem.py

示例3: copy2_fixed

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def copy2_fixed(src, dest):
    # type: (str, str) -> None
    """Wrap shutil.copy2() but map errors copying socket files to
    SpecialFileError as expected.

    See also https://bugs.python.org/issue37700.
    """
    try:
        shutil.copy2(src, dest)
    except (OSError, IOError):
        for f in [src, dest]:
            try:
                is_socket_file = is_socket(f)
            except OSError:
                # An error has already occurred. Another error here is not
                # a problem and we can ignore it.
                pass
            else:
                if is_socket_file:
                    raise shutil.SpecialFileError(
                        "`{f}` is a socket".format(**locals()))

        raise 
开发者ID:ali5h,项目名称:rules_pip,代码行数:25,代码来源:filesystem.py

示例4: copyfile

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def copyfile(self, 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 shutil.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:
            size = os.stat(src).st_size
            with open(src, 'rb') as fsrc:
                with open(dst, 'wb') as fdst:
                    self.copyfileobj(fsrc, fdst, callback=self.draw_copy_progress, total=size)
        return dst 
开发者ID:adafruit,项目名称:pi_video_looper,代码行数:31,代码来源:usb_drive_copymode.py

示例5: test_copyfile_named_pipe

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def test_copyfile_named_pipe(self):
        os.mkfifo(TESTFN)
        try:
            self.assertRaises(shutil.SpecialFileError,
                              shutil.copyfile, TESTFN, TESTFN2)
            self.assertRaises(shutil.SpecialFileError,
                              shutil.copyfile, __file__, TESTFN)
        finally:
            os.remove(TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_shutil.py

示例6: test_copyfile_named_pipe

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def test_copyfile_named_pipe(self):
            os.mkfifo(TESTFN)
            try:
                self.assertRaises(shutil.SpecialFileError,
                                  shutil.copyfile, TESTFN, TESTFN2)
                self.assertRaises(shutil.SpecialFileError,
                                  shutil.copyfile, __file__, TESTFN)
            finally:
                os.remove(TESTFN) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:11,代码来源:test_shutil.py

示例7: test_copyfile_named_pipe

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def test_copyfile_named_pipe(self):
        os.mkfifo(TESTFN)
        try:
            self.assertRaises(shutil.SpecialFileError,
                                shutil.copyfile, TESTFN, TESTFN2)
            self.assertRaises(shutil.SpecialFileError,
                                shutil.copyfile, __file__, TESTFN)
        finally:
            os.remove(TESTFN) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:11,代码来源:test_shutil.py

示例8: test_module_all_attribute

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def test_module_all_attribute(self):
        self.assertTrue(hasattr(shutil, '__all__'))
        target_api = ['copyfileobj', 'copyfile', 'copymode', 'copystat',
                      'copy', 'copy2', 'copytree', 'move', 'rmtree', 'Error',
                      'SpecialFileError', 'ExecError', 'make_archive',
                      'get_archive_formats', 'register_archive_format',
                      'unregister_archive_format', 'get_unpack_formats',
                      'register_unpack_format', 'unregister_unpack_format',
                      'unpack_archive', 'ignore_patterns', 'chown', 'which',
                      'get_terminal_size', 'SameFileError']
        if hasattr(os, 'statvfs') or os.name == 'nt':
            target_api.append('disk_usage')
        self.assertEqual(set(shutil.__all__), set(target_api)) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_shutil.py

示例9: copyFile

# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import SpecialFileError [as 别名]
def copyFile(self, src, dst, buffer_size=10485760, perserveFileDate=True):
        '''
        Copies a file to a new location. Overriding the Apache Commons due to use of larger 
        buffer much faster performance than before.
        @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
        '''
        # 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):
            shutil.copystat(src, dst) 
开发者ID:vital2,项目名称:vital-development,代码行数:40,代码来源:RegenerateConfFiles.py


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