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


Python errno.EXDEV属性代码示例

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


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

示例1: setUpFaultyRename

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def setUpFaultyRename(self):
        """
        Set up a C{os.rename} that will fail with L{errno.EXDEV} on first call.
        This is used to simulate a cross-device rename failure.

        @return: a list of pair (src, dest) of calls to C{os.rename}
        @rtype: C{list} of C{tuple}
        """
        invokedWith = []
        def faultyRename(src, dest):
            invokedWith.append((src, dest))
            if len(invokedWith) == 1:
                raise OSError(errno.EXDEV, 'Test-induced failure simulating '
                                           'cross-device rename failure')
            return originalRename(src, dest)

        originalRename = os.rename
        self.patch(os, "rename", faultyRename)
        return invokedWith 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:21,代码来源:test_paths.py

示例2: lzc_snaprange_space_translate_error

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def lzc_snaprange_space_translate_error(ret, firstsnap, lastsnap):
    if ret == 0:
        return
    if ret == errno.EXDEV and firstsnap is not None:
        if _pool_name(firstsnap) != _pool_name(lastsnap):
            raise lzc_exc.PoolsDiffer(lastsnap)
        else:
            raise lzc_exc.SnapshotMismatch(lastsnap)
    if ret == errno.EINVAL:
        if not _is_valid_snap_name(firstsnap):
            raise lzc_exc.NameInvalid(firstsnap)
        elif not _is_valid_snap_name(lastsnap):
            raise lzc_exc.NameInvalid(lastsnap)
        elif len(firstsnap) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(firstsnap)
        elif len(lastsnap) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(lastsnap)
        elif _pool_name(firstsnap) != _pool_name(lastsnap):
            raise lzc_exc.PoolsDiffer(lastsnap)
        else:
            raise lzc_exc.SnapshotMismatch(lastsnap)
    if ret == errno.ENOENT:
        raise lzc_exc.SnapshotNotFound(lastsnap)
    raise _generic_exception(ret, lastsnap, "Failed to calculate space used by range of snapshots") 
开发者ID:ClusterHQ,项目名称:pyzfs,代码行数:26,代码来源:_error_translation.py

示例3: moveTo

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def moveTo(self, destination):
        try:
            os.rename(self.path, destination.path)
            self.restat(False)
        except OSError, ose:
            if ose.errno == errno.EXDEV:
                # man 2 rename, ubuntu linux 5.10 "breezy":

                #   oldpath and newpath are not on the same mounted filesystem.
                #   (Linux permits a filesystem to be mounted at multiple
                #   points, but rename(2) does not work across different mount
                #   points, even if the same filesystem is mounted on both.)

                # that means it's time to copy trees of directories!
                secsib = destination.temporarySibling()
                self.copyTo(secsib) # slow
                secsib.moveTo(destination) # visible

                # done creating new stuff.  let's clean me up.
                mysecsib = self.temporarySibling()
                self.moveTo(mysecsib) # visible
                mysecsib.remove() # slow
            else:
                raise 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:26,代码来源:filepath.py

示例4: testCrossMountMoveTo

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def testCrossMountMoveTo(self):
        """
        """
        # Bit of a whitebox test - force os.rename, which moveTo tries
        # before falling back to a slower method, to fail, forcing moveTo to
        # use the slower behavior.
        invokedWith = []
        def faultyRename(src, dest):
            invokedWith.append((src, dest))
            if len(invokedWith) == 2:
                raise OSError(errno.EXDEV, 'Test-induced failure simulating cross-device rename failure')
            return originalRename(src, dest)

        originalRename = os.rename
        os.rename = faultyRename
        try:
            self.testMoveTo()
            # A bit of a sanity check for this whitebox test - if our rename
            # was never invoked, the test has probably fallen into
            # disrepair!
            self.failUnless(len(invokedWith) >= 2)
        finally:
            os.rename = originalRename 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:25,代码来源:test_paths.py

示例5: _createLink

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def _createLink(self, linkGroup, target, opJournal):
        # this is part of a hard link group, attempt making a
        # hardlink.
        linkPath = self.linkGroups[linkGroup]
        opJournal.backup(target)

        try:
            util.createLink(linkPath, target)
            # continue with the next file to restore
            return True
        except OSError, e:
            # ignore failure to create a cross-device symlink.
            # we'll restore the file as if it's not a hard link
            # below
            if e.errno != errno.EXDEV:
                raise 
开发者ID:sassoftware,项目名称:conary,代码行数:18,代码来源:update.py

示例6: move

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def move(self, project):
        """Move this job to project.

        This function will attempt to move this instance of job from
        its original project to a different project.

        :param project:
            The project to move this job to.
        :type project:
            :py:class:`~.project.Project`
        :raises DestinationExistsError:
            If the job is already initialized in project.
        :raises RuntimeError:
            If the job is not initialized or the destination is on a different
            device.
        :raises OSError:
            When the move failed due unexpected file system issues.
        """
        dst = project.open_job(self.statepoint())
        _mkdir_p(project.workspace())
        try:
            os.replace(self.workspace(), dst.workspace())
        except OSError as error:
            if error.errno == errno.ENOENT:
                raise RuntimeError(
                    "Cannot move job '{}', because it is not initialized!".format(self))
            elif error.errno in (errno.EEXIST, errno.ENOTEMPTY, errno.EACCES):
                raise DestinationExistsError(dst)
            elif error.errno == errno.EXDEV:
                raise RuntimeError(
                    "Cannot move jobs across different devices (file systems).")
            else:
                raise error
        self.__dict__.update(dst.__dict__) 
开发者ID:glotzerlab,项目名称:signac,代码行数:36,代码来源:job.py

示例7: test_crossMountMoveTo

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def test_crossMountMoveTo(self):
        """
        C{moveTo} should be able to handle C{EXDEV} error raised by
        C{os.rename} when trying to move a file on a different mounted
        filesystem.
        """
        invokedWith = self.setUpFaultyRename()
        # Bit of a whitebox test - force os.rename, which moveTo tries
        # before falling back to a slower method, to fail, forcing moveTo to
        # use the slower behavior.
        self.test_moveTo()
        # A bit of a sanity check for this whitebox test - if our rename
        # was never invoked, the test has probably fallen into disrepair!
        self.assertTrue(invokedWith) 
开发者ID:proxysh,项目名称:Safejumper-for-Desktop,代码行数:16,代码来源:test_paths.py

示例8: test_chroot_perms_link_cross_device

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def test_chroot_perms_link_cross_device():
  with mock.patch('os.link', spec_set=True, autospec=True) as mock_link:
    expected_errno = errno.EXDEV
    mock_link.side_effect = OSError(expected_errno, os.strerror(expected_errno))

    assert_chroot_perms(Chroot.link) 
开发者ID:pantsbuild,项目名称:pex,代码行数:8,代码来源:test_common.py

示例9: safe_copy

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def safe_copy(source, dest, overwrite=False):
  def do_copy():
    temp_dest = dest + uuid4().hex
    shutil.copy(source, temp_dest)
    os.rename(temp_dest, dest)

  # If the platform supports hard-linking, use that and fall back to copying.
  # Windows does not support hard-linking.
  if hasattr(os, 'link'):
    try:
      os.link(source, dest)
    except OSError as e:
      if e.errno == errno.EEXIST:
        # File already exists.  If overwrite=True, write otherwise skip.
        if overwrite:
          do_copy()
      elif e.errno in (errno.EPERM, errno.EXDEV):
        # For a hard link across devices issue, fall back on copying.
        #
        # For a permission issue, the cause could be one of:
        # 1. We can't read source.
        # 2. We can't write dest.
        # 3. We don't own source but can read it.
        # Although we can't do anything about cases 1 and 2, case 3 is due to
        # `protected_hardlinks` (see: https://www.kernel.org/doc/Documentation/sysctl/fs.txt) and
        # we can fall back to copying in that case.
        #
        # See also https://github.com/pantsbuild/pex/issues/850 where this was discovered.
        do_copy()
      else:
        raise
  elif os.path.exists(dest):
    if overwrite:
      do_copy()
  else:
    do_copy()


# See http://stackoverflow.com/questions/2572172/referencing-other-modules-in-atexit 
开发者ID:pantsbuild,项目名称:pex,代码行数:41,代码来源:common.py

示例10: _attempt_ficlone

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def _attempt_ficlone(src, dst):
    try:
        fcntl.ioctl(dst.fileno(), FICLONE, src.fileno())
        return True
    except OSError as ex:
        if ex.errno not in (errno.EBADF, errno.EINVAL,
                            errno.EOPNOTSUPP, errno.EXDEV):
            raise
        return False 
开发者ID:QubesOS,项目名称:qubes-core-admin,代码行数:11,代码来源:reflink.py

示例11: lzc_snapshot_translate_errors

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def lzc_snapshot_translate_errors(ret, errlist, snaps, props):
    if ret == 0:
        return

    def _map(ret, name):
        if ret == errno.EXDEV:
            pool_names = map(_pool_name, snaps)
            same_pool = all(x == pool_names[0] for x in pool_names)
            if same_pool:
                return lzc_exc.DuplicateSnapshots(name)
            else:
                return lzc_exc.PoolsDiffer(name)
        elif ret == errno.EINVAL:
            if any(not _is_valid_snap_name(s) for s in snaps):
                return lzc_exc.NameInvalid(name)
            elif any(len(s) > MAXNAMELEN for s in snaps):
                return lzc_exc.NameTooLong(name)
            else:
                return lzc_exc.PropertyInvalid(name)

        if ret == errno.EEXIST:
            return lzc_exc.SnapshotExists(name)
        if ret == errno.ENOENT:
            return lzc_exc.FilesystemNotFound(name)
        return _generic_exception(ret, name, "Failed to create snapshot")

    _handle_err_list(ret, errlist, snaps, lzc_exc.SnapshotFailure, _map) 
开发者ID:ClusterHQ,项目名称:pyzfs,代码行数:29,代码来源:_error_translation.py

示例12: lzc_hold_translate_errors

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def lzc_hold_translate_errors(ret, errlist, holds, fd):
    if ret == 0:
        return

    def _map(ret, name):
        if ret == errno.EXDEV:
            return lzc_exc.PoolsDiffer(name)
        elif ret == errno.EINVAL:
            if name:
                pool_names = map(_pool_name, holds.keys())
                if not _is_valid_snap_name(name):
                    return lzc_exc.NameInvalid(name)
                elif len(name) > MAXNAMELEN:
                    return lzc_exc.NameTooLong(name)
                elif any(x != _pool_name(name) for x in pool_names):
                    return lzc_exc.PoolsDiffer(name)
            else:
                invalid_names = [b for b in holds.keys() if not _is_valid_snap_name(b)]
                if invalid_names:
                    return lzc_exc.NameInvalid(invalid_names[0])
        fs_name = None
        hold_name = None
        pool_name = None
        if name is not None:
            fs_name = _fs_name(name)
            pool_name = _pool_name(name)
            hold_name = holds[name]
        if ret == errno.ENOENT:
            return lzc_exc.FilesystemNotFound(fs_name)
        if ret == errno.EEXIST:
            return lzc_exc.HoldExists(name)
        if ret == errno.E2BIG:
            return lzc_exc.NameTooLong(hold_name)
        if ret == errno.ENOTSUP:
            return lzc_exc.FeatureNotSupported(pool_name)
        return _generic_exception(ret, name, "Failed to hold snapshot")

    if ret == errno.EBADF:
        raise lzc_exc.BadHoldCleanupFD()
    _handle_err_list(ret, errlist, holds.keys(), lzc_exc.HoldFailure, _map) 
开发者ID:ClusterHQ,项目名称:pyzfs,代码行数:42,代码来源:_error_translation.py

示例13: lzc_release_translate_errors

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def lzc_release_translate_errors(ret, errlist, holds):
    if ret == 0:
        return
    for _, hold_list in holds.iteritems():
        if not isinstance(hold_list, list):
            raise lzc_exc.TypeError('holds must be in a list')

    def _map(ret, name):
        if ret == errno.EXDEV:
            return lzc_exc.PoolsDiffer(name)
        elif ret == errno.EINVAL:
            if name:
                pool_names = map(_pool_name, holds.keys())
                if not _is_valid_snap_name(name):
                    return lzc_exc.NameInvalid(name)
                elif len(name) > MAXNAMELEN:
                    return lzc_exc.NameTooLong(name)
                elif any(x != _pool_name(name) for x in pool_names):
                    return lzc_exc.PoolsDiffer(name)
            else:
                invalid_names = [b for b in holds.keys() if not _is_valid_snap_name(b)]
                if invalid_names:
                    return lzc_exc.NameInvalid(invalid_names[0])
        elif ret == errno.ENOENT:
            return lzc_exc.HoldNotFound(name)
        elif ret == errno.E2BIG:
            tag_list = holds[name]
            too_long_tags = [t for t in tag_list if len(t) > MAXNAMELEN]
            return lzc_exc.NameTooLong(too_long_tags[0])
        elif ret == errno.ENOTSUP:
            pool_name = None
            if name is not None:
                pool_name = _pool_name(name)
            return lzc_exc.FeatureNotSupported(pool_name)
        else:
            return _generic_exception(ret, name, "Failed to release snapshot hold")

    _handle_err_list(ret, errlist, holds.keys(), lzc_exc.HoldReleaseFailure, _map) 
开发者ID:ClusterHQ,项目名称:pyzfs,代码行数:40,代码来源:_error_translation.py

示例14: lzc_send_translate_error

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def lzc_send_translate_error(ret, snapname, fromsnap, fd, flags):
    if ret == 0:
        return
    if ret == errno.EXDEV and fromsnap is not None:
        if _pool_name(fromsnap) != _pool_name(snapname):
            raise lzc_exc.PoolsDiffer(snapname)
        else:
            raise lzc_exc.SnapshotMismatch(snapname)
    elif ret == errno.EINVAL:
        if (fromsnap is not None and not _is_valid_snap_name(fromsnap) and
                not _is_valid_bmark_name(fromsnap)):
            raise lzc_exc.NameInvalid(fromsnap)
        elif not _is_valid_snap_name(snapname) and not _is_valid_fs_name(snapname):
            raise lzc_exc.NameInvalid(snapname)
        elif fromsnap is not None and len(fromsnap) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(fromsnap)
        elif len(snapname) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(snapname)
        elif fromsnap is not None and _pool_name(fromsnap) != _pool_name(snapname):
            raise lzc_exc.PoolsDiffer(snapname)
    elif ret == errno.ENOENT:
        if (fromsnap is not None and not _is_valid_snap_name(fromsnap) and
                not _is_valid_bmark_name(fromsnap)):
            raise lzc_exc.NameInvalid(fromsnap)
        raise lzc_exc.SnapshotNotFound(snapname)
    elif ret == errno.ENAMETOOLONG:
        if fromsnap is not None and len(fromsnap) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(fromsnap)
        else:
            raise lzc_exc.NameTooLong(snapname)
    raise lzc_exc.StreamIOError(ret) 
开发者ID:ClusterHQ,项目名称:pyzfs,代码行数:33,代码来源:_error_translation.py

示例15: test_move_file_exception_unpacking_unlink

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EXDEV [as 别名]
def test_move_file_exception_unpacking_unlink(self):
        # see issue 22182
        with patch("os.rename", side_effect=OSError(errno.EXDEV, "wrong")), \
             patch("os.unlink", side_effect=OSError("wrong", 1)), \
             self.assertRaises(DistutilsFileError):
            with open(self.source, 'w') as fobj:
                fobj.write('spam eggs')
            move_file(self.source, self.target, verbose=0) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:10,代码来源:test_file_util.py


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