當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。