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


Python errno.EACCES属性代码示例

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


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

示例1: _run

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def _run(self, *args, **kwargs):
        cmd = [self.binary, '-j', self.parallelism]
        if mx.get_opts().very_verbose:
            cmd += ['-v']
        cmd += args

        out = kwargs.get('out', mx.OutputCapture())
        err = kwargs.get('err', subprocess.STDOUT)
        if mx.get_opts().verbose:
            if callable(out) and '-n' not in args:
                out = mx.TeeOutputCapture(out)
            if callable(err):
                err = mx.TeeOutputCapture(err)

        try:
            rc = mx.run(cmd, nonZeroIsFatal=False, out=out, err=err, cwd=self.build_dir)
        except OSError as e:
            if e.errno != errno.EACCES:
                mx.abort('Error executing \'{}\': {}'.format(' '.join(cmd), str(e)))
            mx.logv('{} is not executable. Trying to change permissions...'.format(self.binary))
            os.chmod(self.binary, 0o755)
            self._run(*args, **kwargs)  # retry
        else:
            not rc or mx.abort(rc if mx.get_opts().verbose else out.data)  # pylint: disable=expression-not-assigned 
开发者ID:graalvm,项目名称:mx,代码行数:26,代码来源:mx_native.py

示例2: __getMagicMime

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def __getMagicMime(fName):
    """Uses the magic module to retrieve the file mime.

    The mime could be None if e.g. the file does not exist.
    The second bool tells if it was a permission denied case.
    """
    try:
        # E.g.: 'text/x-shellscript'
        output = __magic.from_file(realpath(fName))
        return output, False
    except OSError as exc:
        if exc.errno == EACCES:
            return None, True
        if exc.errno == ENOENT:
            return None, False
        logging.error(str(exc))
        return None, False
    except Exception as exc:
        # Most probably the file does not exist
        logging.error(str(exc))
        return None, False 
开发者ID:SergeySatskiy,项目名称:codimension,代码行数:23,代码来源:fileutils.py

示例3: get_obj_path

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def get_obj_path(self, obj_type, obj_hash, check_exists = False, relative = False):
        if obj_type == 'data':
            base = self._data_path
        elif obj_type == 'meta':
            base = self._meta_path
        else:
            raise PcoccError('Bad object type {0}'.format(obj_type))

        try:
            os.mkdir(os.path.join(base, obj_hash[:2]))
        except OSError as e:
            if e.errno != errno.EEXIST and e.errno != errno.EACCES:
                raise e

        if check_exists and not os.path.exists(os.path.join(base,
                                                            obj_hash[:2],
                                                            obj_hash)):
            raise PcoccError('Object {} not found in repository {}'.format(
                obj_hash, self.name))

        if relative:
            base = os.path.join('../../', obj_type)

        return os.path.join(base, obj_hash[:2], obj_hash) 
开发者ID:cea-hpc,项目名称:pcocc,代码行数:26,代码来源:ObjectStore.py

示例4: custom_popen

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def custom_popen(cmd):
    """Disconnect cmd from parent fds, read only from stdout.
    """
    # needed for py2exe
    creationflags = 0
    if sys.platform == 'win32':
        creationflags = 0x08000000   # CREATE_NO_WINDOW

    # run command
    try:
        p = Popen(cmd, bufsize=0, stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                  creationflags=creationflags)
    except OSError as ex:
        if ex.errno == errno.ENOENT:
            raise RarCannotExec("Unrar not installed? (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        if ex.errno == errno.EACCES or ex.errno == errno.EPERM:
            raise RarCannotExec("Cannot execute unrar (rarfile.UNRAR_TOOL=%r)" % UNRAR_TOOL)
        raise
    return p 
开发者ID:BasioMeusPuga,项目名称:Lector,代码行数:21,代码来源:rarfile.py

示例5: chkdir

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def chkdir(self, path):
        """Create folder if nonexistent, check for write permission then change into directory"""
        try:
            os.makedirs(path)
            self.show_message(_("Folder created."))
            self.workdir(path)
            return True
        except OSError as exception:
            if exception.errno == errno.EEXIST:
                self.show_message(_("Directory already exists. OK."))
                if os.access(path, os.W_OK):
                    self.workdir(path)
                else:
                    self.show_message(_("Error: no write permission"))
                    self.workdir(self.stdir)
                return True
            elif exception.errno == errno.EACCES:
                self.show_message(_("Permission denied."))
                return False
            else:
                self.show_message(_("Invalid path"))
                self.workdir(self.stdir)
                return True

    # Verzeichnis wechseln 
开发者ID:encarsia,项目名称:gpt,代码行数:27,代码来源:modules.py

示例6: _try_except_permissionerror_iter

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def _try_except_permissionerror_iter(try_iter, except_iter):
    if sys.version_info >= (3, 3):
        try:
            for x in try_iter():
                yield x
        except PermissionError as exc:
            for x in except_iter(exc):
                yield x
    else:
        try:
            for x in try_iter():
                yield x
        except EnvironmentError as exc:
            if exc.errno not in (EPERM, EACCES):
                raise
            else:
                for x in except_iter(exc):
                    yield x 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:20,代码来源:__init__.py

示例7: mkdir

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
        """
        Create a new directory at this given path.
        """
        if self._closed:
            self._raise_closed()

        def _try_func():
            self._accessor.mkdir(self, mode)

        def _exc_func(exc):
            if not parents or self.parent == self:
                raise exc
            self.parent.mkdir(parents=True, exist_ok=True)
            self.mkdir(mode, parents=False, exist_ok=exist_ok)

        try:
            _try_except_filenotfounderror(_try_func, _exc_func)
        except OSError:
            # Cannot rely on checking for EEXIST, since the operating system
            # could give priority to other errors like EACCES or EROFS
            if not exist_ok or not self.is_dir():
                raise 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:25,代码来源:__init__.py

示例8: safe_listdir

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def safe_listdir(path):
    """
    Attempt to list contents of path, but suppress some exceptions.
    """
    try:
        return os.listdir(path)
    except (PermissionError, NotADirectoryError):
        pass
    except OSError as e:
        # Ignore the directory if does not exist, not a directory or
        # permission denied
        ignorable = (
            e.errno in (errno.ENOTDIR, errno.EACCES, errno.ENOENT)
            # Python 2 on Windows needs to be handled this way :(
            or getattr(e, "winerror", None) == 267
        )
        if not ignorable:
            raise
    return () 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:21,代码来源:__init__.py

示例9: _mkstemp_inner

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def _mkstemp_inner(dir, pre, suf, flags):
    """Code common to mkstemp, TemporaryFile, and NamedTemporaryFile."""

    names = _get_candidate_names()

    for seq in xrange(TMP_MAX):
        name = names.next()
        file = _os.path.join(dir, pre + name + suf)
        try:
            fd = _os.open(file, flags, 0600)
            _set_cloexec(fd)
            return (fd, _os.path.abspath(file))
        except OSError, e:
            if e.errno == _errno.EEXIST:
                continue # try again
            if (_os.name == 'nt' and e.errno == _errno.EACCES and
                _os.path.isdir(dir) and _os.access(dir, _os.W_OK)):
                # On windows, when a directory with the chosen name already
                # exists, EACCES error code is returned instead of EEXIST.
                continue
            raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:tempfile.py

示例10: isTipcAvailable

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def isTipcAvailable():
    """Check if the TIPC module is loaded

    The TIPC module is not loaded automatically on Ubuntu and probably
    other Linux distros.
    """
    if not hasattr(socket, "AF_TIPC"):
        return False
    try:
        f = open("/proc/modules")
    except IOError as e:
        # It's ok if the file does not exist, is a directory or if we
        # have not the permission to read it. In any other case it's a
        # real error, so raise it again.
        if e.errno in (errno.ENOENT, errno.EISDIR, errno.EACCES):
            return False
        else:
            raise
    with f:
        for line in f:
            if line.startswith("tipc "):
                return True
    return False 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_socket.py

示例11: setUpModule

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def setUpModule():
    global OLD_SYS_PATH
    OLD_SYS_PATH = sys.path[:]

    if site.ENABLE_USER_SITE and not os.path.isdir(site.USER_SITE):
        # need to add user site directory for tests
        try:
            os.makedirs(site.USER_SITE)
            # modify sys.path: will be restored by tearDownModule()
            site.addsitedir(site.USER_SITE)
        except OSError as exc:
            if exc.errno in (errno.EACCES, errno.EPERM):
                raise unittest.SkipTest('unable to create user site directory (%r): %s'
                                        % (site.USER_SITE, exc))
            else:
                raise 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_site.py

示例12: test_remove_negative

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def test_remove_negative(self):
        import stat
        self.assertRaisesNumber(WindowsError, errno.ENOENT, lambda : nt.remove('some_file_that_does_not_exist'))
        try:
            file('some_test_file.txt', 'w').close()
            nt.chmod('some_test_file.txt', stat.S_IREAD)
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            
            f = file('some_test_file.txt', 'w+')
            self.assertRaisesNumber(WindowsError, errno.EACCES, lambda : nt.remove('some_test_file.txt'))
            f.close()
        finally:
            nt.chmod('some_test_file.txt', stat.S_IWRITE)
            nt.unlink('some_test_file.txt')
            
            

    # rename tests 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_nt.py

示例13: lock

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def lock(self):
        if self.handle is None or self.handle.closed:
            self.handle = open(self.path, "w+")
            self.fd = self.handle.fileno()
        if (self.flags & fcntl.LOCK_NB) != 0 or self.seconds is None:
            try:
                fcntl.flock(self.handle, self.flags)
            except IOError as e:
                if e.errno not in [errno.EACCES, errno.EAGAIN]:
                    raise e
                raise Locked(self.path)
        else:
            with timeout(self.seconds):
                try:
                    fcntl.flock(self.handle, self.flags)
                except IOError as e:
                    errnos = [errno.EINTR, errno.EACCES, errno.EAGAIN]
                    if e.errno not in errnos:
                        raise e
                    raise Timeout(self.path) 
开发者ID:mesosphere-backup,项目名称:deimos,代码行数:22,代码来源:flock.py

示例14: wrap_exceptions

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def wrap_exceptions(fun):
    """Call callable into a try/except clause and translate ENOENT,
    EACCES and EPERM in NoSuchProcess or AccessDenied exceptions.
    """

    def wrapper(self, *args, **kwargs):
        try:
            return fun(self, *args, **kwargs)
        except EnvironmentError as err:
            # support for private module import
            if (NoSuchProcess is None or AccessDenied is None or
                    ZombieProcess is None):
                raise
            # ENOENT (no such file or directory) gets raised on open().
            # ESRCH (no such process) can get raised on read() if
            # process is gone in meantime.
            if err.errno in (errno.ENOENT, errno.ESRCH):
                if not pid_exists(self.pid):
                    raise NoSuchProcess(self.pid, self._name)
                else:
                    raise ZombieProcess(self.pid, self._name, self._ppid)
            if err.errno in (errno.EPERM, errno.EACCES):
                raise AccessDenied(self.pid, self._name)
            raise
    return wrapper 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:27,代码来源:_psaix.py

示例15: _send_signal

# 需要导入模块: import errno [as 别名]
# 或者: from errno import EACCES [as 别名]
def _send_signal(self, sig):
            assert not self.pid < 0, self.pid
            if self.pid == 0:
                # see "man 2 kill"
                raise ValueError(
                    "preventing sending signal to process with PID 0 as it "
                    "would affect every process in the process group of the "
                    "calling process (os.getpid()) instead of PID 0")
            try:
                os.kill(self.pid, sig)
            except OSError as err:
                if err.errno == errno.ESRCH:
                    if OPENBSD and pid_exists(self.pid):
                        # We do this because os.kill() lies in case of
                        # zombie processes.
                        raise ZombieProcess(self.pid, self._name, self._ppid)
                    else:
                        self._gone = True
                        raise NoSuchProcess(self.pid, self._name)
                if err.errno in (errno.EPERM, errno.EACCES):
                    raise AccessDenied(self.pid, self._name)
                raise 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:24,代码来源:__init__.py


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