本文整理匯總了Python中stat.S_ISFIFO屬性的典型用法代碼示例。如果您正苦於以下問題:Python stat.S_ISFIFO屬性的具體用法?Python stat.S_ISFIFO怎麽用?Python stat.S_ISFIFO使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類stat
的用法示例。
在下文中一共展示了stat.S_ISFIFO屬性的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: copyfile
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [as 別名]
def copyfile(src, dst):
"""Copy data from src to dst"""
if _samefile(src, dst):
raise Error("`%s` and `%s` are the same file" % (src, dst))
for fn in [src, dst]:
try:
st = os.stat(fn)
except OSError:
# File most likely does not exist
pass
else:
# XXX What about other special files? (sockets, devices...)
if stat.S_ISFIFO(st.st_mode):
raise SpecialFileError("`%s` is a named pipe" % fn)
with open(src, 'rb') as fsrc:
with open(dst, 'wb') as fdst:
copyfileobj(fsrc, fdst)
示例2: __hashEntry
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [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
示例3: mode_filetype
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [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 "???"
示例4: check_fileaccessible
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [as 別名]
def check_fileaccessible(this_path):
'''
檢查文件是否可以訪問
:parm
file:需要檢查的文件,支持當前相對路徑、~、或者絕對路徑
:return
返回一個(執行結果代碼,原因)
執行結果代碼:Flase失敗,True成功
原因:成功為True,失敗為失敗原因
'''
result = path_isexists(this_path)
if result[0] :
this_path = result[1]
else :
return result
if not os.path.isfile(this_path) :
return (False, '路徑存在,但不是一個文件')
if not (os.path.isfile(this_path) or stat.S_ISFIFO(os.stat(this_path).st_mode)):
return (False, "該文件沒有權限訪問")
return (True, this_path)
示例5: compress
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [as 別名]
def compress(self, files_to_compress=None):
"""
Compress the output files of a job object.
Args:
files_to_compress (list): A list of files to compress (optional)
"""
# delete empty files
if files_to_compress is None:
files_to_compress = [
f for f in list(self.list_files())
if (f not in ["rho.sxb", "waves.sxb"]
and not stat.S_ISFIFO(os.stat(os.path.join(
self.working_directory, f
)).st_mode))
]
for f in list(self.list_files()):
filename = os.path.join(self.working_directory, f)
if (
f not in files_to_compress
and os.path.exists(filename)
and os.stat(filename).st_size == 0
):
os.remove(filename)
super(SphinxBase, self).compress(files_to_compress=files_to_compress)
示例6: _stdin_is_tty
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [as 別名]
def _stdin_is_tty(self):
"""Detect whether the stdin is mapped to a terminal console.
I found this technique in the answer by thg435 here:
http://stackoverflow.com/questions/13442574/how-do-i-determine-if-sys-stdin-is-redirected-from-a-file-vs-piped-from-another
"""
import os
import stat
mode = os.fstat(0).st_mode
if ((not stat.S_ISFIFO(mode)) and # piped
(not stat.S_ISREG(mode))): # redirected
return True
else:
# not piped or redirected, so assume terminal input
return False
示例7: __init__
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import S_ISFIFO [as 別名]
def __init__(self, loop, pipe, protocol, waiter=None, extra=None):
super().__init__(extra)
self._extra['pipe'] = pipe
self._loop = loop
self._pipe = pipe
self._fileno = pipe.fileno()
mode = os.fstat(self._fileno).st_mode
if not (stat.S_ISFIFO(mode) or
stat.S_ISSOCK(mode) or
stat.S_ISCHR(mode)):
raise ValueError("Pipe transport is for pipes/sockets only.")
_set_nonblocking(self._fileno)
self._protocol = protocol
self._closing = False
self._loop.call_soon(self._protocol.connection_made, self)
# only start reading when connection_made() has been called
self._loop.call_soon(self._loop.add_reader,
self._fileno, self._read_ready)
if waiter is not None:
# only wake up the waiter when connection_made() has been called
self._loop.call_soon(futures._set_result_unless_cancelled,
waiter, None)