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


Python stat.S_ISDIR属性代码示例

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


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

示例1: is_dir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def is_dir(self, follow_symlinks=True):
        """
        Return 'True' if this entry is a directory or a symbolic link pointing to a directory; return 'False' if the
        entry is or points to any other kind of file, or if it doesn't exist anymore.

        If follow_symlinks is 'False', return 'True' only if this entry is a directory (without following symlinks);
        return 'False' if the entry is any other kind of file.

        The result is cached on the 'smcblient.DirEntry' object, with a separate cache for follow_symlinks 'True' and
        'False'. Call 'smbclient.path.isdir(entry.path)' to fetch up-to-date information.

        On the first, uncached call, no SMB call is required unless the path is a reparse point.

        :param follow_symlinks: Whether to check if the entry's target is a directory (True) or the entry itself
            (False) if the entry is a symlink.
        :return: bool that states whether the entry is a directory or not.
        """
        is_lnk = self.is_symlink()
        if follow_symlinks and is_lnk:
            return self._link_target_type_check(py_stat.S_ISDIR)
        else:
            # Python behaviour is to consider a symlink not a directory even if it has the DIRECTORY attribute.
            return not is_lnk and self._dir_info['file_attributes'].has_flag(FileAttributes.FILE_ATTRIBUTE_DIRECTORY) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:25,代码来源:_os.py

示例2: info

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def info(self, path):
        s = self.ftp.stat(path)
        if S_ISDIR(s.st_mode):
            t = "directory"
        elif S_ISLNK(s.st_mode):
            t = "link"
        else:
            t = "file"
        return {
            "name": path + "/" if t == "directory" else path,
            "size": s.st_size,
            "type": t,
            "uid": s.st_uid,
            "gid": s.st_gid,
            "time": s.st_atime,
            "mtime": s.st_mtime,
        } 
开发者ID:intake,项目名称:filesystem_spec,代码行数:19,代码来源:sftp.py

示例3: __hashEntry

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def __hashEntry(self, prefix, entry, s):
        if stat.S_ISREG(s.st_mode):
            digest = self.__index.check(prefix, entry, s, hashFile)
        elif stat.S_ISDIR(s.st_mode):
            digest = self.__hashDir(prefix, entry)
        elif stat.S_ISLNK(s.st_mode):
            digest = self.__index.check(prefix, entry, s, DirHasher.__hashLink)
        elif stat.S_ISBLK(s.st_mode) or stat.S_ISCHR(s.st_mode):
            digest = struct.pack("<L", s.st_rdev)
        elif stat.S_ISFIFO(s.st_mode):
            digest = b''
        else:
            digest = b''
            logging.getLogger(__name__).warning("Unknown file: %s", entry)

        return digest 
开发者ID:BobBuildTool,项目名称:bob,代码行数:18,代码来源:utils.py

示例4: _rmtree

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def _rmtree(path):
        try:
            shutil.rmtree(path)
            return
        except EnvironmentError:
            pass

        def _rmtree_inner(path):
            for name in _force_run(path, os.listdir, path):
                fullname = os.path.join(path, name)
                try:
                    mode = os.lstat(fullname).st_mode
                except EnvironmentError:
                    mode = 0
                if stat.S_ISDIR(mode):
                    _rmtree_inner(fullname)
                    _force_run(path, os.rmdir, fullname)
                else:
                    _force_run(path, os.unlink, fullname)
        _rmtree_inner(path)
        os.rmdir(path) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:__init__.py

示例5: mode_filetype

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def mode_filetype(mode):
    mode = stat.S_IFMT(mode)
    dic = {
            stat.S_ISFIFO: "fifo file",
            stat.S_ISCHR: "character device",
            stat.S_ISDIR: "directory",
            stat.S_ISBLK: "block device",
            stat.S_ISREG: "regular file",
            stat.S_ISLNK: "symbolic link",
            stat.S_ISSOCK: "socket",
            stat.S_ISDOOR: "door",
            }
    for test_func, name in dic.items():
        if test_func(mode):
            return name
    return "???" 
开发者ID:nil0x42,项目名称:phpsploit,代码行数:18,代码来源:plugin.py

示例6: isdir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def isdir(path, **kwargs):
    """
    Return True if path is an existing directory. This follows symbolic links, so both islink() and isdir() can be true
    for the same path.

    :param path: The path to check.
    :param kwargs: Common arguments used to build the SMB Session.
    :return: True if path is a dir or points to a dir.
    """
    return _stat_ismode(path, py_stat.S_ISDIR, True, **kwargs) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:12,代码来源:path.py

示例7: test_mkdir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def test_mkdir(smb_share):
    dirname = ntpath.join(smb_share, 'dir')
    smbclient.mkdir(dirname)
    actual = smbclient.stat(dirname)
    assert stat.S_ISDIR(actual.st_mode)

    expected = "[NtStatus 0xc0000035] File exists:"
    with pytest.raises(SMBOSError, match=re.escape(expected)):
        smbclient.mkdir(dirname) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:11,代码来源:test_smbclient_os.py

示例8: test_makedirs_missing_parents

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def test_makedirs_missing_parents(smb_share):
    dirpath = ntpath.join(smb_share, 'missing', 'missing', 'folder')
    smbclient.makedirs(dirpath)
    assert stat.S_ISDIR(smbclient.stat(dirpath).st_mode) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:6,代码来源:test_smbclient_os.py

示例9: test_stat_directory

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def test_stat_directory(smb_share):
    actual = smbclient.stat(smb_share)
    assert isinstance(actual, smbclient.SMBStatResult)
    assert actual[0] == actual.st_mode
    assert actual[1] == actual.st_ino
    assert actual[2] == actual.st_dev
    assert actual[3] == actual.st_nlink
    assert actual[4] == actual.st_uid
    assert actual[5] == actual.st_gid
    assert actual[6] == actual.st_size
    assert actual[7] == actual.st_atime
    assert actual[8] == actual.st_mtime
    assert actual[9] == actual.st_ctime
    assert actual[10] == actual.st_chgtime
    assert actual[11] == actual.st_atime_ns
    assert actual[12] == actual.st_mtime_ns
    assert actual[13] == actual.st_ctime_ns
    assert actual[14] == actual.st_chgtime_ns
    assert actual[15] == actual.st_file_attributes
    assert actual[16] == actual.st_reparse_tag

    assert stat.S_ISDIR(actual.st_mode)
    assert not stat.S_ISREG(actual.st_mode)
    assert not stat.S_ISLNK(actual.st_mode)
    assert actual.st_nlink == 1
    assert actual.st_gid == 0
    assert actual.st_uid == 0
    assert actual.st_size == 0
    assert actual.st_ctime is not None
    assert actual.st_chgtime is not None
    assert actual.st_atime is not None
    assert actual.st_mtime is not None
    assert actual.st_ctime_ns is not None
    assert actual.st_chgtime_ns is not None
    assert actual.st_atime_ns is not None
    assert actual.st_mtime_ns is not None
    assert actual.st_file_attributes == FileAttributes.FILE_ATTRIBUTE_DIRECTORY
    assert actual.st_reparse_tag == 0 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:40,代码来源:test_smbclient_os.py

示例10: _rmtree_unsafe

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def _rmtree_unsafe(path, onerror):
    try:
        if os.path.islink(path):
            # symlinks to directories are forbidden, see bug #1669
            raise OSError("Cannot call rmtree on a symbolic link")
    except OSError:
        onerror(os.path.islink, path, sys.exc_info())
        # can't continue even if onerror hook returns
        return
    names = []
    try:
        names = os.listdir(path)
    except os.error:
        onerror(os.listdir, path, sys.exc_info())
    for name in names:
        fullname = os.path.join(path, name)
        try:
            mode = os.lstat(fullname).st_mode
        except os.error:
            mode = 0
        if stat.S_ISDIR(mode):
            _rmtree_unsafe(fullname, onerror)
        else:
            try:
                os.unlink(fullname)
            except os.error:
                onerror(os.unlink, fullname, sys.exc_info())
    try:
        os.rmdir(path)
    except os.error:
        onerror(os.rmdir, path, sys.exc_info())

# Version using fd-based APIs to protect against races 
开发者ID:war-and-code,项目名称:jawfish,代码行数:35,代码来源:shutil.py

示例11: isdir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def isdir(s):
    """Return true if the pathname refers to an existing directory."""
    try:
        st = os.stat(s)
    except os.error:
        return False
    return stat.S_ISDIR(st.st_mode) 
开发者ID:war-and-code,项目名称:jawfish,代码行数:9,代码来源:genericpath.py

示例12: _get_default_cache_dir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def _get_default_cache_dir(self):
        def _unsafe_dir():
            raise RuntimeError('Cannot determine safe temp directory.  You '
                               'need to explicitly provide one.')

        tmpdir = tempfile.gettempdir()

        # On windows the temporary directory is used specific unless
        # explicitly forced otherwise.  We can just use that.
        if os.name == 'nt':
            return tmpdir
        if not hasattr(os, 'getuid'):
            _unsafe_dir()

        dirname = '_jinja2-cache-%d' % os.getuid()
        actual_dir = os.path.join(tmpdir, dirname)

        try:
            os.mkdir(actual_dir, stat.S_IRWXU)
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise
        try:
            os.chmod(actual_dir, stat.S_IRWXU)
            actual_dir_stat = os.lstat(actual_dir)
            if actual_dir_stat.st_uid != os.getuid() \
               or not stat.S_ISDIR(actual_dir_stat.st_mode) \
               or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
                _unsafe_dir()
        except OSError as e:
            if e.errno != errno.EEXIST:
                raise

        actual_dir_stat = os.lstat(actual_dir)
        if actual_dir_stat.st_uid != os.getuid() \
           or not stat.S_ISDIR(actual_dir_stat.st_mode) \
           or stat.S_IMODE(actual_dir_stat.st_mode) != stat.S_IRWXU:
            _unsafe_dir()

        return actual_dir 
开发者ID:remg427,项目名称:misp42splunk,代码行数:42,代码来源:bccache.py

示例13: isdir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def isdir(self):
        return S_ISDIR(self._osstatresult.st_mode) 
开发者ID:pytest-dev,项目名称:py,代码行数:4,代码来源:local.py

示例14: dir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def dir(self):
            return S_ISDIR(self._stat().mode) 
开发者ID:pytest-dev,项目名称:py,代码行数:4,代码来源:local.py

示例15: findall

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDIR [as 别名]
def findall(self):
        """Find all files under the base and set ``allfiles`` to the absolute
        pathnames of files found.
        """
        from stat import S_ISREG, S_ISDIR, S_ISLNK

        self.allfiles = allfiles = []
        root = self.base
        stack = [root]
        pop = stack.pop
        push = stack.append

        while stack:
            root = pop()
            names = os.listdir(root)

            for name in names:
                fullname = os.path.join(root, name)

                # Avoid excess stat calls -- just one will do, thank you!
                stat = os.stat(fullname)
                mode = stat.st_mode
                if S_ISREG(mode):
                    allfiles.append(fsdecode(fullname))
                elif S_ISDIR(mode) and not S_ISLNK(mode):
                    push(fullname) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:28,代码来源:manifest.py


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