本文整理汇总了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)
示例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)
示例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
示例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,
}
示例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
示例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 "???"
示例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)
示例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
示例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
示例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)
示例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
示例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
示例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)
示例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)
示例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)