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