本文整理匯總了Python中stat.ST_DEV屬性的典型用法代碼示例。如果您正苦於以下問題:Python stat.ST_DEV屬性的具體用法?Python stat.ST_DEV怎麽用?Python stat.ST_DEV使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在類stat
的用法示例。
在下文中一共展示了stat.ST_DEV屬性的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: emit
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def emit(self, record):
"""
Emit a record.
First check if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
if not os.path.exists(self.baseFilename):
stat = None
changed = 1
else:
stat = os.stat(self.baseFilename)
changed = (stat[ST_DEV] != self.dev) or (stat[ST_INO] != self.ino)
if changed and self.stream is not None:
self.stream.flush()
self.stream.close()
self.stream = self._open()
if stat is None:
stat = os.stat(self.baseFilename)
self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
logging.FileHandler.emit(self, record)
示例2: test_pex_builder_copy_or_link
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def test_pex_builder_copy_or_link():
with nested(temporary_dir(), temporary_dir(), temporary_dir()) as (td1, td2, td3):
src = os.path.join(td1, 'exe.py')
with open(src, 'w') as fp:
fp.write(exe_main)
def build_and_check(path, copy):
pb = PEXBuilder(path=path, copy=copy)
pb.add_source(src, 'exe.py')
path_clone = os.path.join(path, '__clone')
pb.clone(into=path_clone)
for root in path, path_clone:
s1 = os.stat(src)
s2 = os.stat(os.path.join(root, 'exe.py'))
is_link = (s1[stat.ST_INO], s1[stat.ST_DEV]) == (s2[stat.ST_INO], s2[stat.ST_DEV])
if copy:
assert not is_link
else:
assert is_link
build_and_check(td2, False)
build_and_check(td3, True)
示例3: reopen_file
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def reopen_file(self):
try:
# stat the file by path, checking for existence
sres = os.stat(self.baseFilename)
except OSError as err:
if err.errno == errno.ENOENT:
sres = None
else:
raise
# compare file system stat with that of our stream file handle
if (not sres or
sres[stat.ST_DEV] != self.dev or
sres[stat.ST_INO] != self.ino):
if self.stream is not None:
# we have an open file handle, clean it up
self.stream.flush()
self.stream.close()
self.stream = None
# open a new file handle and get new stat info from that fd
self.stream = self._open()
self._statstream()
示例4: _statstream
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def _statstream(self):
if self.stream:
sres = os.fstat(self.stream.fileno())
self.dev, self.ino = sres[ST_DEV], sres[ST_INO]
示例5: emit
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def emit(self, record):
"""
Emit a record.
First check if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
# Reduce the chance of race conditions by stat'ing by path only
# once and then fstat'ing our new fd if we opened a new log stream.
# See issue #14632: Thanks to John Mulligan for the problem report
# and patch.
try:
# stat the file by path, checking for existence
sres = os.stat(self.baseFilename)
except OSError as err:
if err.errno == errno.ENOENT:
sres = None
else:
raise
# compare file system stat with that of our stream file handle
if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino:
if self.stream is not None:
# we have an open file handle, clean it up
self.stream.flush()
self.stream.close()
# open a new file handle and get new stat info from that fd
self.stream = self._open()
self._statstream()
logging.FileHandler.emit(self, record)
示例6: __init__
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def __init__(self, filename, mode='a', encoding=None, delay=0):
logging.FileHandler.__init__(self, filename, mode, encoding, delay)
if not os.path.exists(self.baseFilename):
self.dev, self.ino = -1, -1
else:
stat = os.stat(self.baseFilename)
self.dev, self.ino = stat[ST_DEV], stat[ST_INO]
示例7: emit
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def emit(self, record):
"""
Emit a record.
First check if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
# Reduce the chance of race conditions by stat'ing by path only
# once and then fstat'ing our new fd if we opened a new log stream.
# See issue #14632: Thanks to John Mulligan for the problem report
# and patch.
try:
# stat the file by path, checking for existence
sres = os.stat(self.baseFilename)
except OSError as err:
if err.errno == errno.ENOENT:
sres = None
else:
raise
# compare file system stat with that of our stream file handle
if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino:
if self.stream is not None:
# we have an open file handle, clean it up
self.stream.flush()
self.stream.close()
self.stream = None # See Issue #21742: _open () might fail.
# open a new file handle and get new stat info from that fd
self.stream = self._open()
self._statstream()
logging.FileHandler.emit(self, record)
示例8: is_same_hard_link
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def is_same_hard_link(filename:str, other:str):
s1 = os.stat(filename)
s2 = os.stat(other)
return (s1[stat.ST_INO], s1[stat.ST_DEV]) == \
(s2[stat.ST_INO], s2[stat.ST_DEV])
# MetaDB tables
示例9: emit
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def emit(self, record):
"""
Emit a record.
First check if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
# Reduce the chance of race conditions by stat'ing by path only
# once and then fstat'ing our new fd if we opened a new log stream.
# See issue #14632: Thanks to John Mulligan for the problem report
# and patch.
try:
# stat the file by path, checking for existence
sres = os.stat(self.baseFilename)
except FileNotFoundError:
sres = None
# compare file system stat with that of our stream file handle
if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino:
if self.stream is not None:
# we have an open file handle, clean it up
self.stream.flush()
self.stream.close()
self.stream = None # See Issue #21742: _open () might fail.
# open a new file handle and get new stat info from that fd
self.stream = self._open()
self._statstream()
logging.FileHandler.emit(self, record)
示例10: reopenIfNeeded
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def reopenIfNeeded(self):
"""
Reopen log file if needed.
Checks if the underlying file has changed, and if it
has, close the old stream and reopen the file to get the
current stream.
"""
# Reduce the chance of race conditions by stat'ing by path only
# once and then fstat'ing our new fd if we opened a new log stream.
# See issue #14632: Thanks to John Mulligan for the problem report
# and patch.
try:
# stat the file by path, checking for existence
sres = os.stat(self.baseFilename)
except FileNotFoundError:
sres = None
# compare file system stat with that of our stream file handle
if not sres or sres[ST_DEV] != self.dev or sres[ST_INO] != self.ino:
if self.stream is not None:
# we have an open file handle, clean it up
self.stream.flush()
self.stream.close()
self.stream = None # See Issue #21742: _open () might fail.
# open a new file handle and get new stat info from that fd
self.stream = self._open()
self._statstream()
示例11: acquire
# 需要導入模塊: import stat [as 別名]
# 或者: from stat import ST_DEV [as 別名]
def acquire(self):
"""Returns True if file has been changed, False otherwise"""
ret = False
while True:
if not self.file:
self.file = open(self.path, 'a')
self.fstatd = os.fstat(self.file.fileno())
ret = True
try:
fcntl.flock(self.file, fcntl.LOCK_EX)
except Exception:
try:
self.file.close()
except Exception:
pass
self.file = None
raise
try:
statd = os.stat(self.path)
except FileNotFoundError:
try:
self.file.close()
except Exception:
pass
self.file = None
continue
except Exception:
try:
self.file.close()
except Exception:
pass
self.file = None
raise
if self.fstatd[stat.ST_DEV] == statd[stat.ST_DEV] and \
self.fstatd[stat.ST_INO] == statd[stat.ST_INO]:
return ret
self.file.close()
self.file = None