當前位置: 首頁>>代碼示例>>Python>>正文


Python errno.ENOTEMPTY屬性代碼示例

本文整理匯總了Python中errno.ENOTEMPTY屬性的典型用法代碼示例。如果您正苦於以下問題:Python errno.ENOTEMPTY屬性的具體用法?Python errno.ENOTEMPTY怎麽用?Python errno.ENOTEMPTY使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在errno的用法示例。


在下文中一共展示了errno.ENOTEMPTY屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _delete_measures_files_for_metric

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def _delete_measures_files_for_metric(self, metric_id, files):
        for f in files:
            try:
                os.unlink(self._build_measure_path(metric_id, f))
            except OSError as e:
                # Another process deleted it in the meantime, no prob'
                if e.errno != errno.ENOENT:
                    raise
        try:
            os.rmdir(self._build_measure_path(metric_id))
        except OSError as e:
            # ENOENT: ok, it has been removed at almost the same time
            #         by another process
            # ENOTEMPTY: ok, someone pushed measure in the meantime,
            #            we'll delete the measures and directory later
            # EEXIST: some systems use this instead of ENOTEMPTY
            if e.errno not in (errno.ENOENT, errno.ENOTEMPTY, errno.EEXIST):
                raise 
開發者ID:gnocchixyz,項目名稱:gnocchi,代碼行數:20,代碼來源:file.py

示例2: _testAtomicityOfNonEmptyDirectoryRenamesTask

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def _testAtomicityOfNonEmptyDirectoryRenamesTask(parent, child, _):
    tmpChildDir = tempfile.mkdtemp(dir=parent, prefix='child', suffix='.tmp')
    grandChild = os.path.join(tmpChildDir, 'grandChild')
    open(grandChild, 'w').close()
    grandChildId = os.stat(grandChild).st_ino
    try:
        os.rename(tmpChildDir, child)
    except OSError as e:
        if e.errno == errno.ENOTEMPTY or e.errno == errno.EEXIST:
            os.unlink(grandChild)
            os.rmdir(tmpChildDir)
            return None
        else:
            raise
    else:
        # We won the race
        return grandChildId 
開發者ID:DataBiosphere,項目名稱:toil,代碼行數:19,代碼來源:systemTest.py

示例3: download

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def download(self, callback=None):
        """
        Downloads this resource from its URL to a file on the local system. This method should
        only be invoked on a worker node after the node was setup for accessing resources via
        prepareSystem().
        """
        dirPath = self.localDirPath
        if not os.path.exists(dirPath):
            tempDirPath = mkdtemp(dir=os.path.dirname(dirPath), prefix=self.contentHash + "-")
            self._save(tempDirPath)
            if callback is not None:
                callback(tempDirPath)
            try:
                os.rename(tempDirPath, dirPath)
            except OSError as e:
                # If dirPath already exists & is non-empty either ENOTEMPTY or EEXIST will be raised
                if e.errno == errno.ENOTEMPTY or e.errno == errno.EEXIST:
                    # Another process beat us to it.
                    # TODO: This is correct but inefficient since multiple processes download the resource redundantly
                    pass
                else:
                    raise 
開發者ID:DataBiosphere,項目名稱:toil,代碼行數:24,代碼來源:resource.py

示例4: remove_data

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def remove_data(self):
        if self.path is not None:
            for child in self.items:
                child.remove_data()
            for child in self.folders:
                child.remove_data()
            try:
                # The json file must be removed first. Otherwise the rmdir will fail.
                if os.path.exists(self.get_json_path()):
                    os.remove(self.get_json_path())
                os.rmdir(self.path)
            except OSError as err:
                # There may be user data in the removed directory. Only swallow the error, if it is caused by
                # residing user data. Other errors should propagate.
                if err.errno != errno.ENOTEMPTY:
                    raise 
開發者ID:autokey,項目名稱:autokey,代碼行數:18,代碼來源:model.py

示例5: __init__

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def __init__(self, ntstatus, filename, filename2=None):
        self.ntstatus = ntstatus
        self.filename2 = to_native(filename2) if filename2 else None

        ntstatus_name = 'STATUS_UNKNOWN'
        for name, val in vars(NtStatus).items():
            if ntstatus == val:
                ntstatus_name = name
                break

        error_details = {
            NtStatus.STATUS_OBJECT_NAME_NOT_FOUND: errno.ENOENT,
            NtStatus.STATUS_OBJECT_PATH_NOT_FOUND: errno.ENOENT,
            NtStatus.STATUS_OBJECT_NAME_COLLISION: errno.EEXIST,
            NtStatus.STATUS_PRIVILEGE_NOT_HELD: (errno.EACCES, "Required privilege not held"),
            NtStatus.STATUS_SHARING_VIOLATION: (errno.EPERM, "The process cannot access the file because it is being "
                                                             "used by another process"),
            NtStatus.STATUS_NOT_A_REPARSE_POINT: (errno.EINVAL, "The file or directory is not a reparse point"),
            NtStatus.STATUS_FILE_IS_A_DIRECTORY: errno.EISDIR,
            NtStatus.STATUS_NOT_A_DIRECTORY: errno.ENOTDIR,
            NtStatus.STATUS_DIRECTORY_NOT_EMPTY: errno.ENOTEMPTY,
            NtStatus.STATUS_END_OF_FILE: getattr(errno, 'ENODATA', 120),  # Not present on py2 for Windows.
        }.get(ntstatus, (0, "Unknown NtStatus error returned '%s'" % ntstatus_name))

        if not isinstance(error_details, tuple):
            error_details = (error_details, os.strerror(error_details))

        super(SMBOSError, self).__init__(error_details[0], error_details[1], to_native(filename)) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:30,代碼來源:exceptions.py

示例6: remove_empty_directory

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def remove_empty_directory(directory):
    """
    Remove a directory if it is empty.

    :param directory: The pathname of the directory (a string).
    """
    try:
        os.rmdir(directory)
    except OSError as e:
        if e.errno not in (errno.ENOTEMPTY, errno.ENOENT):
            raise 
開發者ID:paylogic,項目名稱:py2deb,代碼行數:13,代碼來源:hooks.py

示例7: move

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [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

示例8: _copy_to_job_workspace

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def _copy_to_job_workspace(src, job, copytree):
    dst = job.workspace()
    try:
        copytree(src, dst)
    except (IOError, OSError) as error:
        if error.errno in (errno.ENOTEMPTY, errno.EEXIST):
            raise DestinationExistsError(job)
        raise
    else:
        job._init()
    return dst 
開發者ID:glotzerlab,項目名稱:signac,代碼行數:13,代碼來源:import_export.py

示例9: test_atomic_directory_finalize_enotempty

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def test_atomic_directory_finalize_enotempty():
  atomic_directory_finalize_test(errno.ENOTEMPTY) 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:4,代碼來源:test_common.py

示例10: finalize

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def finalize(self, source=None):
    """Rename `work_dir` to `target_dir` using `os.rename()`.

    :param str source: An optional source offset into the `work_dir`` to use for the atomic
                       update of `target_dir`. By default the whole `work_dir` is used.

    If a race is lost and `target_dir` already exists, the `target_dir` dir is left unchanged and
    the `work_dir` directory will simply be removed.
    """
    if self.is_finalized:
      return

    source = os.path.join(self._work_dir, source) if source else self._work_dir
    try:
      # Perform an atomic rename.
      #
      # Per the docs: https://docs.python.org/2.7/library/os.html#os.rename
      #
      #   The operation may fail on some Unix flavors if src and dst are on different filesystems.
      #   If successful, the renaming will be an atomic operation (this is a POSIX requirement).
      #
      # We have satisfied the single filesystem constraint by arranging the `work_dir` to be a
      # sibling of the `target_dir`.
      os.rename(source, self._target_dir)
    except OSError as e:
      if e.errno not in (errno.EEXIST, errno.ENOTEMPTY):
        raise e
    finally:
      self.cleanup() 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:31,代碼來源:common.py

示例11: ensure_dir

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def ensure_dir(path):
    # type: (AnyStr) -> None
    """os.path.makedirs without EEXIST."""
    try:
        os.makedirs(path)
    except OSError as e:
        # Windows can raise spurious ENOTEMPTY errors. See #6426.
        if e.errno != errno.EEXIST and e.errno != errno.ENOTEMPTY:
            raise 
開發者ID:pantsbuild,項目名稱:pex,代碼行數:11,代碼來源:misc.py

示例12: _remove_empty_dir

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def _remove_empty_dir(path):
    try:
        os.rmdir(path)
        _fsync_path(os.path.dirname(path))
        LOGGER.info('Removed empty directory: %s', path)
    except OSError as ex:
        if ex.errno not in (errno.ENOENT, errno.ENOTEMPTY):
            raise 
開發者ID:QubesOS,項目名稱:qubes-core-admin,代碼行數:10,代碼來源:reflink.py

示例13: test_rmdir

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def test_rmdir(alice_workspace):
    await alice_workspace.mkdir("/foz")
    await alice_workspace.rmdir("/foz")
    lst = await alice_workspace.listdir("/")
    assert lst == [FsPath("/foo")]

    with pytest.raises(OSError) as context:
        await alice_workspace.rmdir("/foo")
    assert context.value.errno == errno.ENOTEMPTY

    with pytest.raises(NotADirectoryError):
        await alice_workspace.rmdir("/foo/bar")

    with pytest.raises(PermissionError):
        await alice_workspace.rmdir("/") 
開發者ID:Scille,項目名稱:parsec-cloud,代碼行數:17,代碼來源:test_workspace_fs.py

示例14: rmdir_p

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def rmdir_p(self):
        """ Like :meth:`rmdir`, but does not raise an exception if the
        directory is not empty or does not exist. """
        try:
            self.rmdir()
        except OSError:
            _, e, _ = sys.exc_info()
            if e.errno != errno.ENOTEMPTY and e.errno != errno.EEXIST:
                raise
        return self 
開發者ID:click-contrib,項目名稱:click-configfile,代碼行數:12,代碼來源:path.py

示例15: removedirs_p

# 需要導入模塊: import errno [as 別名]
# 或者: from errno import ENOTEMPTY [as 別名]
def removedirs_p(self):
        """ Like :meth:`removedirs`, but does not raise an exception if the
        directory is not empty or does not exist. """
        try:
            self.removedirs()
        except OSError:
            _, e, _ = sys.exc_info()
            if e.errno != errno.ENOTEMPTY and e.errno != errno.EEXIST:
                raise
        return self

    # --- Modifying operations on files 
開發者ID:click-contrib,項目名稱:click-configfile,代碼行數:14,代碼來源:path.py


注:本文中的errno.ENOTEMPTY屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。