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


Python stat.S_ISLNK屬性代碼示例

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


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

示例1: test_symlink_file_existing_src

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def test_symlink_file_existing_src(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    with smbclient.open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    smbclient.symlink(src_filename, dst_filename)

    actual_files = smbclient.listdir(smb_share)
    assert 'link.txt' in actual_files
    assert 'file.txt' in actual_files

    actual = smbclient.lstat(dst_filename)
    assert stat.S_ISLNK(actual.st_mode)
    assert actual.st_file_attributes == (
        FileAttributes.FILE_ATTRIBUTE_REPARSE_POINT | FileAttributes.FILE_ATTRIBUTE_ARCHIVE) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:19,代碼來源:test_smbclient_os.py

示例2: test_symlink_relative_src

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def test_symlink_relative_src(smb_share):
    src_filename = "%s\\dir1\\file.txt" % smb_share
    dst_filename = "%s\\dir2\\link.txt" % smb_share

    smbclient.mkdir("%s\\dir1" % smb_share)
    smbclient.mkdir("%s\\dir2" % smb_share)

    with smbclient.open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    smbclient.symlink("..\\dir1\\file.txt", dst_filename)

    with smbclient.open_file(dst_filename) as fd:
        assert fd.read() == u"content"

    actual = smbclient.lstat(dst_filename)
    assert stat.S_ISLNK(actual.st_mode)
    assert actual.st_file_attributes == (
        FileAttributes.FILE_ATTRIBUTE_REPARSE_POINT | FileAttributes.FILE_ATTRIBUTE_ARCHIVE) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:21,代碼來源:test_smbclient_os.py

示例3: __call__

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def __call__(self, step):
        slavever = step.slaveVersion('stat')
        if not slavever:
            raise BuildSlaveTooOldError("slave is too old, does not know "
                                        "about stat")

        def commandComplete(cmd):
            if cmd.rc != 0:
                return False

            s = cmd.updates["stat"][-1]
            filemode = s[stat.ST_MODE]
            if stat.S_ISREG(filemode) or stat.S_ISLNK(filemode):
                # True only if this is a file or a link and not any other file
                # system object.
                return True
            else:
                return False

        cmd = LoggedRemoteCommand('stat', {'file': self.filename})
        d = step.runCommand(cmd)
        d.addCallback(lambda res: commandComplete(cmd))
        return d 
開發者ID:llvm,項目名稱:llvm-zorg,代碼行數:25,代碼來源:FileConditions.py

示例4: info

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

示例5: __hashEntry

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

示例6: mode_filetype

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

示例7: assert_islink

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def assert_islink(path, to=None, msg=None):
    """Assert that path exists and is a symlink.
    
    If to is specified, also check that it is the target of the symlink.
    """
    path = _strpath(path)
    st = _stat_for_assert(path, False, msg)
    if not stat.S_ISLNK(st.st_mode):
        if msg is None:
            msg = "Path exists, but is not a symlink: %r" % path
        raise AssertionError(msg)
    
    if to is not None:
        to = _strpath(to)
        target = os.readlink(path)
        # TODO: Normalise the target to an absolute path?
        if target != to:
            if msg is None:
                msg = _link_target_msg.format(path=path, expected=to, actual=target)
            raise AssertionError(msg) 
開發者ID:jupyter,項目名稱:testpath,代碼行數:22,代碼來源:asserts.py

示例8: sizeClassifier

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def sizeClassifier(path, min_size=DEFAULTS['min_size']):
    """Sort a file into a group based on on-disk size.

    :param paths: See :func:`fastdupes.groupify`

    :param min_size: Files smaller than this size (in bytes) will be ignored.
    :type min_size: :class:`__builtins__.int`

    :returns: See :func:`fastdupes.groupify`

    .. todo:: Rework the calling of :func:`~os.stat` to minimize the number of
        calls. It's a fairly significant percentage of the time taken according
        to the profiler.
    """
    filestat = _stat(path)
    if stat.S_ISLNK(filestat.st_mode):
        return  # Skip symlinks.

    if filestat.st_size < min_size:
        return  # Skip files below the size limit

    return filestat.st_size 
開發者ID:ssokolow,項目名稱:fastdupes,代碼行數:24,代碼來源:fastdupes.py

示例9: list_item

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def list_item(path):
	try:
		_stat = os.lstat(path)

		if path.endswith(os.path.sep):
			path = path.rsplit(os.path.sep, 1)[0]

		name = os.path.basename(path)

		if stat.S_ISLNK(_stat.st_mode):
			try:
				name += ' -> ' + os.readlink(path)
			except:
				pass

		return {
			'name': common.decode2utf8(name),
			'type': file_op.identifytype(path),
			'size': common.size_human_readable(_stat.st_size),
			'ts': time_op.timestamp2string(int(_stat.st_mtime))
		}
	except Exception as e:
		return None 
開發者ID:turingsec,項目名稱:marsnake,代碼行數:25,代碼來源:list_files.py

示例10: islink

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def islink(path, **kwargs):
    """
    Return True if path is a symbolic link.

    :param path: The path to check
    :param kwargs: Common arguments used to build the SMB Session.
    :return: True if path is a symlink.
    """
    return _stat_ismode(path, py_stat.S_ISLNK, False, **kwargs) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:11,代碼來源:path.py

示例11: test_lstat_on_symlink_file

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def test_lstat_on_symlink_file(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    with smbclient.open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    smbclient.symlink(src_filename, dst_filename)

    actual_src = smbclient.stat(src_filename)
    actual = smbclient.lstat(dst_filename)
    assert actual.st_ino != actual_src.st_ino
    assert stat.S_ISLNK(actual.st_mode)
    assert actual.st_reparse_tag == ReparseTags.IO_REPARSE_TAG_SYMLINK 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:16,代碼來源:test_smbclient_os.py

示例12: test_stat_directory

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

示例13: test_stat_symlink_dont_follow

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def test_stat_symlink_dont_follow(smb_share):
    src_filename = "%s\\file.txt" % smb_share
    dst_filename = "%s\\link.txt" % smb_share

    with smbclient.open_file(src_filename, mode='w') as fd:
        fd.write(u"content")

    smbclient.symlink(src_filename, dst_filename)

    actual_src = smbclient.stat(src_filename)
    actual = smbclient.stat(dst_filename, follow_symlinks=False)
    assert actual.st_ino != actual_src.st_ino
    assert stat.S_ISLNK(actual.st_mode) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:15,代碼來源:test_smbclient_os.py

示例14: test_symlink_dir_missing_src

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def test_symlink_dir_missing_src(smb_share):
    src_dirname = "%s\\dir" % smb_share
    dst_dirname = "%s\\link" % smb_share

    smbclient.symlink(src_dirname, dst_dirname, target_is_directory=True)

    assert smbclient.listdir(smb_share) == ['link']
    actual = smbclient.lstat(dst_dirname)
    assert stat.S_ISLNK(actual.st_mode)
    assert actual.st_file_attributes == (
        FileAttributes.FILE_ATTRIBUTE_DIRECTORY | FileAttributes.FILE_ATTRIBUTE_REPARSE_POINT) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:13,代碼來源:test_smbclient_os.py

示例15: test_symlink_dir_existing_src

# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISLNK [as 別名]
def test_symlink_dir_existing_src(smb_share):
    src_dirname = "%s\\dir" % smb_share
    dst_dirname = "%s\\link" % smb_share

    smbclient.mkdir(src_dirname)

    smbclient.symlink(src_dirname, dst_dirname)

    actual_dirs = smbclient.listdir(smb_share)
    assert 'link' in actual_dirs
    assert 'dir' in actual_dirs
    actual = smbclient.lstat(dst_dirname)
    assert stat.S_ISLNK(actual.st_mode)
    assert actual.st_file_attributes == (
        FileAttributes.FILE_ATTRIBUTE_DIRECTORY | FileAttributes.FILE_ATTRIBUTE_REPARSE_POINT) 
開發者ID:jborean93,項目名稱:smbprotocol,代碼行數:17,代碼來源:test_smbclient_os.py


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