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


Python errno.EROFS属性代码示例

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


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

示例1: makedirs

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def makedirs(p):
    """
    Recursive directory creation (like mkdir -p).
    Returns True if the path is successfully created, False if it existed
    already, and raises an OSError on other error conditions.
    """
    try:
        os.makedirs(p)
        return True
    except OSError as e:
        # EEXIST is fine (directory already existed).  We also occasionally get
        # EROFS when making directories in SNAP_COMMON. I am not quite sure
        # what is going on there. Re-raise any other errors.
        if e.errno == errno.EEXIST:
            pass
        elif e.errno == errno.EROFS:
            print("Read-only filesystem error occurred while making {}".format(p))
        else:
            raise e
    return False 
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:22,代码来源:pdosq.py

示例2: test_mount_options

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def test_mount_options(self):
        """
        ``mount`` accepts mount options such as ``ro``.
        """
        filename = random_name(self)
        filecontent = random_name(self)
        mount_directory = self.make_temporary_directory()
        with mount(
                self.device.device,
                mount_directory,
                options=["ro"]
        ) as mountpoint:
            e = self.assertRaises(
                OSError,
                mountpoint.child(filename).setContent,
                filecontent
            )
            self.assertEqual(errno.EROFS, e.errno) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:20,代码来源:test_blockdevice_manager.py

示例3: returns_sftp_error

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def returns_sftp_error(func):

    def wrapped(*args, **kwargs):
        try:
            return func(*args, **kwargs)
        except OSError as err:
            LOG.debug("Error calling %s(%s, %s): %s",
                      func, args, kwargs, err, exc_info=True)
            errno = err.errno
            if errno in {EACCES, EDQUOT, EPERM, EROFS}:
                return paramiko.SFTP_PERMISSION_DENIED
            if errno in {ENOENT, ENOTDIR}:
                return paramiko.SFTP_NO_SUCH_FILE
            return paramiko.SFTP_FAILURE
        except Exception as err:
            LOG.debug("Error calling %s(%s, %s): %s",
                      func, args, kwargs, err, exc_info=True)
            return paramiko.SFTP_FAILURE

    return wrapped 
开发者ID:carletes,项目名称:mock-ssh-server,代码行数:22,代码来源:sftp.py

示例4: try_makedirs

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def try_makedirs(cache_dir: Path) -> bool:
    """Attempts to create the given directory and sub-directories exist, returns True if
    successful or it already exists"""
    try:
        os.makedirs(fspath(cache_dir), exist_ok=True)
    except (FileNotFoundError, NotADirectoryError, FileExistsError):
        # One of the path components was not a directory:
        # - we're in a zip file
        # - it is a file
        return False
    except PermissionError:
        return False
    except OSError as e:
        # as of now, EROFS doesn't have an equivalent OSError-subclass
        if e.errno == errno.EROFS:
            return False
        raise
    return True 
开发者ID:pytest-dev,项目名称:pytest,代码行数:20,代码来源:rewrite.py

示例5: write_operation

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def write_operation(f):
    @wraps(f)
    def decorated(*args, **kwargs):
        if not fetch_successful.is_set() or not push_successful.is_set():
            raise FuseOSError(EROFS)

        global writers
        writers += 1

        if syncing.is_set():
            log.debug("WriteOperation: Wait until syncing is done")
            sync_done.wait()

        try:
            result = f(*args, **kwargs)
        finally:
            writers -= 1

        return result

    return decorated 
开发者ID:presslabs,项目名称:gitfs,代码行数:23,代码来源:write_operation.py

示例6: __init__

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def __init__(self, path, factory=None, create=True):
        """Initialize a single-file mailbox."""
        Mailbox.__init__(self, path, factory, create)
        try:
            f = open(self._path, 'rb+')
        except OSError as e:
            if e.errno == errno.ENOENT:
                if create:
                    f = open(self._path, 'wb+')
                else:
                    raise NoSuchMailboxError(self._path)
            elif e.errno in (errno.EACCES, errno.EROFS):
                f = open(self._path, 'rb')
            else:
                raise
        self._file = f
        self._toc = None
        self._next_key = 0
        self._pending = False       # No changes require rewriting the file.
        self._pending_sync = False  # No need to sync the file
        self._locked = False
        self._file_length = None    # Used to record mailbox size 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:24,代码来源:mailbox.py

示例7: rename

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def rename(self, old_path, new_path):  # {{{3
        try:
            self.__log_call('rename', 'rename(%r -> %r)', old_path, new_path)
            if self.read_only: return -errno.EROFS
            # Try to remove the existing target path (if if exists).
            # NB: This also makes sure target directories are empty.
            try:
                self.__remove(new_path, check_empty=True)
            except OSError, e:
                # Ignore errno.ENOENT, re raise other exceptions.
                if e.errno != errno.ENOENT: raise
            # Link the new path to the same inode as the old path.
            self.link(old_path, new_path, nested=True)
            # Finally unlink the old path.
            self.unlink(old_path, nested=True)
            self.__commit_changes()
            self.__gc_hook()
            return 0 
开发者ID:SlavikMIPT,项目名称:tgcloud,代码行数:20,代码来源:dedupfs.py

示例8: _shareLock

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def _shareLock(db):
    """
    Take a share lock on the database syslock when an optional migration might
    run. If it conflicts due to an ongoing update then bail out.
    """
    if db.database == ':memory:':
        # Nothing to lock
        return None, True
    lockPath = os.path.join(os.path.dirname(db.database), 'syslock')
    try:
        lockFile = open(lockPath, 'r+')
        fcntl.lockf(lockFile.fileno(), fcntl.LOCK_SH | fcntl.LOCK_NB)
    except IOError as err:
        if err.args[0] in (errno.EAGAIN, errno.EACCES, errno.EROFS):
            # Busy or no write access; skip optional migrations
            return None, False
        elif err.args[0] == errno.ENOENT:
            # Database has never been locked. Probably running in a testsuite,
            # so proceed anyway.
            return None, True
        raise
    return lockFile, True 
开发者ID:sassoftware,项目名称:conary,代码行数:24,代码来源:schema.py

示例9: test_fake_open_write

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def test_fake_open_write(self):
    self.mox.ReplayAll()
    with self.assertRaises(OSError) as cm:
      stubs.fake_open(__file__, os.O_RDWR)
    self.mox.VerifyAll()
    e = cm.exception
    self.assertEqual(errno.EROFS, e.errno)
    self.assertEqual('Read-only file system', e.strerror)
    self.assertEqual(__file__, e.filename)
    self.mox.VerifyAll() 
开发者ID:elsigh,项目名称:browserscope,代码行数:12,代码来源:stubs_test.py

示例10: __init__

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def __init__(self, filename, mode='r', bufsize=-1, **kwargs):
    """Initializer. See file built-in documentation."""
    if mode not in FakeFile.ALLOWED_MODES:
      raise IOError(errno.EROFS, 'Read-only file system', filename)

    if not FakeFile.is_file_accessible(filename):
      raise IOError(errno.EACCES, 'file not accessible', filename)

    super(FakeFile, self).__init__(filename, mode, bufsize, **kwargs) 
开发者ID:elsigh,项目名称:browserscope,代码行数:11,代码来源:stubs.py

示例11: __init__

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def __init__(self, path, factory=None, create=True):
        """Initialize a single-file mailbox."""
        Mailbox.__init__(self, path, factory, create)
        try:
            f = open(self._path, 'rb+')
        except IOError, e:
            if e.errno == errno.ENOENT:
                if create:
                    f = open(self._path, 'wb+')
                else:
                    raise NoSuchMailboxError(self._path)
            elif e.errno in (errno.EACCES, errno.EROFS):
                f = open(self._path, 'rb')
            else:
                raise 
开发者ID:glmcdona,项目名称:meddle,代码行数:17,代码来源:mailbox.py

示例12: _lock_file

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def _lock_file(f, dotlock=True):
    """Lock file f using lockf and dot locking."""
    dotlock_done = False
    try:
        if fcntl:
            try:
                fcntl.lockf(f, fcntl.LOCK_EX | fcntl.LOCK_NB)
            except IOError, e:
                if e.errno in (errno.EAGAIN, errno.EACCES, errno.EROFS):
                    raise ExternalClashError('lockf: lock unavailable: %s' %
                                             f.name)
                else:
                    raise
        if dotlock:
            try:
                pre_lock = _create_temporary(f.name + '.lock')
                pre_lock.close()
            except IOError, e:
                if e.errno in (errno.EACCES, errno.EROFS):
                    return  # Without write access, just skip dotlocking.
                else:
                    raise
            try:
                if hasattr(os, 'link'):
                    os.link(pre_lock.name, f.name + '.lock')
                    dotlock_done = True
                    os.unlink(pre_lock.name)
                else:
                    os.rename(pre_lock.name, f.name + '.lock')
                    dotlock_done = True
            except OSError, e:
                if e.errno == errno.EEXIST or \
                  (os.name == 'os2' and e.errno == errno.EACCES):
                    os.remove(pre_lock.name)
                    raise ExternalClashError('dot lock unavailable: %s' %
                                             f.name)
                else:
                    raise 
开发者ID:glmcdona,项目名称:meddle,代码行数:40,代码来源:mailbox.py

示例13: assertReadOnly

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def assertReadOnly(self, path):
        """
        Assert writes are not possible to the given filesystem path.

        :param FilePath path: Directory which ought to be read-only.
        """
        exc = self.assertRaises(OSError,
                                path.child(b"text").setContent, b"hello")
        self.assertEqual(exc.args[0], errno.EROFS) 
开发者ID:ClusterHQ,项目名称:flocker,代码行数:11,代码来源:test_filesystems_zfs.py

示例14: lzc_receive_translate_error

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def lzc_receive_translate_error(ret, snapname, fd, force, origin, props):
    if ret == 0:
        return
    if ret == errno.EINVAL:
        if not _is_valid_snap_name(snapname) and not _is_valid_fs_name(snapname):
            raise lzc_exc.NameInvalid(snapname)
        elif len(snapname) > MAXNAMELEN:
            raise lzc_exc.NameTooLong(snapname)
        elif origin is not None and not _is_valid_snap_name(origin):
            raise lzc_exc.NameInvalid(origin)
        else:
            raise lzc_exc.BadStream()
    if ret == errno.ENOENT:
        if not _is_valid_snap_name(snapname):
            raise lzc_exc.NameInvalid(snapname)
        else:
            raise lzc_exc.DatasetNotFound(snapname)
    if ret == errno.EEXIST:
        raise lzc_exc.DatasetExists(snapname)
    if ret == errno.ENOTSUP:
        raise lzc_exc.StreamFeatureNotSupported()
    if ret == errno.ENODEV:
        raise lzc_exc.StreamMismatch(_fs_name(snapname))
    if ret == errno.ETXTBSY:
        raise lzc_exc.DestinationModified(_fs_name(snapname))
    if ret == errno.EBUSY:
        raise lzc_exc.DatasetBusy(_fs_name(snapname))
    if ret == errno.ENOSPC:
        raise lzc_exc.NoSpace(_fs_name(snapname))
    if ret == errno.EDQUOT:
        raise lzc_exc.QuotaExceeded(_fs_name(snapname))
    if ret == errno.ENAMETOOLONG:
        raise lzc_exc.NameTooLong(snapname)
    if ret == errno.EROFS:
        raise lzc_exc.ReadOnlyPool(_pool_name(snapname))
    if ret == errno.EAGAIN:
        raise lzc_exc.SuspendedPool(_pool_name(snapname))

    raise lzc_exc.StreamIOError(ret) 
开发者ID:ClusterHQ,项目名称:pyzfs,代码行数:41,代码来源:_error_translation.py

示例15: test_try_makedirs

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EROFS [as 别名]
def test_try_makedirs(monkeypatch, tmp_path: Path) -> None:
    from _pytest.assertion.rewrite import try_makedirs

    p = tmp_path / "foo"

    # create
    assert try_makedirs(p)
    assert p.is_dir()

    # already exist
    assert try_makedirs(p)

    # monkeypatch to simulate all error situations
    def fake_mkdir(p, exist_ok=False, *, exc):
        assert isinstance(p, str)
        raise exc

    monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=FileNotFoundError()))
    assert not try_makedirs(p)

    monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=NotADirectoryError()))
    assert not try_makedirs(p)

    monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=PermissionError()))
    assert not try_makedirs(p)

    err = OSError()
    err.errno = errno.EROFS
    monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=err))
    assert not try_makedirs(p)

    # unhandled OSError should raise
    err = OSError()
    err.errno = errno.ECHILD
    monkeypatch.setattr(os, "makedirs", partial(fake_mkdir, exc=err))
    with pytest.raises(OSError) as exc_info:
        try_makedirs(p)
    assert exc_info.value.errno == errno.ECHILD 
开发者ID:pytest-dev,项目名称:pytest,代码行数:40,代码来源:test_assertrewrite.py


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