本文整理汇总了Python中stat.ST_INO属性的典型用法代码示例。如果您正苦于以下问题:Python stat.ST_INO属性的具体用法?Python stat.ST_INO怎么用?Python stat.ST_INO使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.ST_INO属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: emit
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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_INO [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_INO [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: testLinkGroups
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [as 别名]
def testLinkGroups(self):
srcVersion = self.addCompAndPackage('foo:runtime', '1.0-1-1',
fileContents = [
('/bin/onefile', rephelp.RegularFile(
linkGroup = '\1'*16,
contents = 'contents',
perms = 0700) ),
('/bin/anotherfile', rephelp.RegularFile(
linkGroup = '\1'*16,
contents = 'contents',
perms = 0700) ),
] )
pkgTrv, runtimeTrv = self.buildDerivation('foo', srcVersion,
"r.Link('yetanother', '/bin/onefile')",
returnTrove = [ 'foo', ':runtime' ])
self.updatePkg('%s=%s' % (pkgTrv.getName(), pkgTrv.getVersion()))
inode1 = os.stat(self.rootDir+'/bin/onefile')[stat.ST_INO]
inode2 = os.stat(self.rootDir+'/bin/anotherfile')[stat.ST_INO]
inode3 = os.stat(self.rootDir+'/bin/yetanother')[stat.ST_INO]
self.assertEqual(inode1, inode2)
self.assertEqual(inode1, inode3)
示例5: testLinkTestGood
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [as 别名]
def testLinkTestGood(self):
recipestr2 = """
class TestLink(PackageRecipe):
name = 'test'
version = '0'
clearBuildReqs()
def setup(r):
r.macros.foo = '/foo'
r.macros.bar = 'bar'
r.Create('%(foo)s',
contents='ABCDEFGABCDEFGABCDEFGABCDEFG%(destdir)s/')
r.Link('%(bar)s', 'blah', '%(foo)s')
"""
self.reset()
(built, d) = self.buildRecipe(recipestr2, "TestLink")
for p in built:
self.updatePkg(self.workDir, p[0], p[1])
a = os.lstat(util.joinPaths(self.workDir, 'foo'))
b = os.lstat(util.joinPaths(self.workDir, 'bar'))
c = os.lstat(util.joinPaths(self.workDir, 'blah'))
assert(a[stat.ST_INO] == b[stat.ST_INO])
assert(b[stat.ST_INO] == c[stat.ST_INO])
示例6: _statstream
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [as 别名]
def _statstream(self):
if self.stream:
sres = os.fstat(self.stream.fileno())
self.dev, self.ino = sres[ST_DEV], sres[ST_INO]
示例7: emit
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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)
示例8: __init__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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]
示例9: emit
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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)
示例10: write_last_stat
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [as 别名]
def write_last_stat(self, f, offset):
st = os.fstat(f.fileno())
ino = st[stat.ST_INO]
last = {
"inode": ino,
"offset": offset,
}
fsutil.write_file(self.stat_path(), utfjson.dump(last), fsync=False)
logger.info('position written fn=%s inode=%d offset=%d' % (
self.fn, ino, offset))
示例11: get_last_offset
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [as 别名]
def get_last_offset(self, f, default_seek):
st = os.fstat(f.fileno())
ino = st[stat.ST_INO]
size = st[stat.ST_SIZE]
max_residual = None
if default_seek is None or default_seek == SEEK_START:
default_offset = 0
elif default_seek == SEEK_END:
default_offset = size
elif default_seek < 0:
max_residual = 0 - default_seek
default_offset = max(size - max_residual, 0)
else:
default_offset = default_seek
stat_file = self.stat_path()
if not os.path.isfile(stat_file):
return default_offset
try:
last = self.read_last_stat()
except (IOError, ValueError):
# damaged stat file
return default_offset
if max_residual is not None:
if size - last['offset'] > max_residual:
last['offset'] = size - max_residual
if last['inode'] != ino or last['offset'] > size:
return default_offset
return last['offset']
示例12: is_same_hard_link
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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
示例13: test_dataset_add_with_copy
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [as 别名]
def test_dataset_add_with_copy(tmpdir, runner, project, client):
"""Test adding data to dataset with copy."""
import os
import stat
# create a dataset
result = runner.invoke(cli, ['dataset', 'create', 'my-dataset'])
assert 0 == result.exit_code
assert 'OK' in result.output
paths = []
original_inodes = []
for i in range(3):
new_file = tmpdir.join('file_{0}'.format(i))
new_file.write(str(i))
original_inodes.append(os.lstat(str(new_file))[stat.ST_INO])
paths.append(str(new_file))
# add data
result = runner.invoke(
cli,
['dataset', 'add', 'my-dataset'] + paths,
)
assert 0 == result.exit_code
received_inodes = []
with client.with_dataset('my-dataset') as dataset:
assert dataset.name == 'my-dataset'
for file_ in dataset.files:
path_ = (client.path / file_.path).resolve()
received_inodes.append(os.lstat(str(path_))[stat.ST_INO])
# check that original inodes are within created ones
for inode in received_inodes:
assert inode not in original_inodes
示例14: emit
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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)
示例15: reopenIfNeeded
# 需要导入模块: import stat [as 别名]
# 或者: from stat import ST_INO [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()