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