本文整理汇总了Python中stat.S_ISDOOR属性的典型用法代码示例。如果您正苦于以下问题:Python stat.S_ISDOOR属性的具体用法?Python stat.S_ISDOOR怎么用?Python stat.S_ISDOOR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.S_ISDOOR属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mode_filetype
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDOOR [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 "???"
示例2: ls
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISDOOR [as 别名]
def ls(self, path: str = '.', attrs: bool = False, keep_alive: bool = False, **kwargs) \
-> Union[List[str], Dict[str, Any]]:
"""
Return the list of files in a path on a remote server.
:param path: Remote path (default: current directory).
:param keep_alive: Keep the connection active after running the command (default: False).
:param attrs: Set to True if you want to get the full information of each file (default: False).
:param kwargs: Arguments for :meth:`platypush.plugins.ssh.SshPlugin.connect`.
:return: A list of filenames if ``attrs=False``, otherwise a dictionary ``filename -> {attributes`` if
``attrs=True``.
"""
client = self._connect(**kwargs)
sftp = client.open_sftp()
def get_file_type(st_mode: int) -> str:
if S_ISDIR(st_mode):
return 'directory'
elif S_ISBLK(st_mode):
return 'block'
elif S_ISCHR(st_mode):
return 'device'
elif S_ISDOOR(st_mode):
return 'door'
elif S_ISREG(st_mode):
return 'file'
elif S_ISLNK(st_mode):
return 'link'
elif S_ISFIFO(st_mode):
return 'fifo'
elif S_ISSOCK(st_mode):
return 'sock'
else:
return 'unknown'
try:
if attrs:
return {
f.filename: {
'filename': f.filename,
'longname': f.longname,
'attributes': f.attr,
'type': get_file_type(f.st_mode),
'access_time': datetime.datetime.fromtimestamp(f.st_atime),
'modify_time': datetime.datetime.fromtimestamp(f.st_mtime),
'uid': f.st_uid,
'gid': f.st_gid,
'size': f.st_size,
}
for f in sftp.listdir_attr(path)
}
else:
return sftp.listdir(path)
finally:
if not keep_alive:
host, port, user = self._get_host_port_user(**kwargs)
self.disconnect(host=host, port=port, user=user)