本文整理匯總了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)