本文整理汇总了Python中stat.S_ISREG属性的典型用法代码示例。如果您正苦于以下问题:Python stat.S_ISREG属性的具体用法?Python stat.S_ISREG怎么用?Python stat.S_ISREG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.S_ISREG属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: is_file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def is_file(self, follow_symlinks=True):
"""
Return 'True' if this entry is a file or a symbolic link pointing to a file; return 'False' if the entry is or
points to a directory or other non-file entry.
If follow_symlinks is 'False', return 'True' only if this entry is a file (without following symlinks); return
'False' if entry is a directory or other non-file entry.
The result is cached on the 'smcblient.DirEntry' object, with a separate cache for follow_symlinks 'True' and
'False'. Call 'smbclient.path.isfile(entry.path)' to fetch up-to-date information.
On the first, uncached call, no SMB call is required unless the path is a reparse point.
:param follow_symlinks: Whether to check if the entry's target is a file (True) or the entry itself (False) if
the entry is a symlink.
:return: bool that states whether the entry is a file or not.
"""
is_lnk = self.is_symlink()
if follow_symlinks and is_lnk:
return self._link_target_type_check(py_stat.S_ISREG)
else:
# Python behaviour is to consider a symlink not a file even if it does not have the DIRECTORY attribute.
return not is_lnk and \
not self._dir_info['file_attributes'].has_flag(FileAttributes.FILE_ATTRIBUTE_DIRECTORY)
示例2: __call__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def __call__(self, step):
slavever = step.slaveVersion('stat')
if not slavever:
raise BuildSlaveTooOldError("slave is too old, does not know "
"about stat")
def commandComplete(cmd):
if cmd.rc != 0:
return False
s = cmd.updates["stat"][-1]
filemode = s[stat.ST_MODE]
if stat.S_ISREG(filemode) or stat.S_ISLNK(filemode):
# True only if this is a file or a link and not any other file
# system object.
return True
else:
return False
cmd = LoggedRemoteCommand('stat', {'file': self.filename})
d = step.runCommand(cmd)
d.addCallback(lambda res: commandComplete(cmd))
return d
示例3: __hashEntry
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [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
示例4: mode_filetype
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [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 "???"
示例5: open_files
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def open_files(self, ret, info):
self.assertIsInstance(ret, list)
for f in ret:
self.assertIsInstance(f.fd, int)
self.assertIsInstance(f.path, str)
if WINDOWS:
self.assertEqual(f.fd, -1)
elif LINUX:
self.assertIsInstance(f.position, int)
self.assertIsInstance(f.mode, str)
self.assertIsInstance(f.flags, int)
self.assertGreaterEqual(f.position, 0)
self.assertIn(f.mode, ('r', 'w', 'a', 'r+', 'a+'))
self.assertGreater(f.flags, 0)
elif BSD and not f.path:
# XXX see: https://github.com/giampaolo/psutil/issues/595
continue
assert os.path.isabs(f.path), f
try:
st = os.stat(f.path)
except FileNotFoundError:
pass
else:
assert stat.S_ISREG(st.st_mode), f
示例6: _cbGetFileSize
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def _cbGetFileSize(self, attrs, rf, lf):
if not stat.S_ISREG(attrs['permissions']):
rf.close()
lf.close()
return "Can't get non-regular file: %s" % rf.name
rf.size = attrs['size']
bufferSize = self.client.transport.conn.options['buffersize']
numRequests = self.client.transport.conn.options['requests']
rf.total = 0.0
dList = []
chunks = []
startTime = self.reactor.seconds()
for i in range(numRequests):
d = self._cbGetRead('', rf, lf, chunks, 0, bufferSize, startTime)
dList.append(d)
dl = defer.DeferredList(dList, fireOnOneErrback=1)
dl.addCallback(self._cbGetDone, rf, lf)
return dl
示例7: isfile
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def isfile(path, **kwargs):
"""
Return True if path is an existing regular file. This follows symbolic links, so both islink() and isfile() can be
true for the same path.
:param path: The path to check.
:param kwargs: Common arguments used to build the SMB Session.
:return: True if the path is a file or points to a file.
"""
return _stat_ismode(path, py_stat.S_ISREG, True, **kwargs)
示例8: test_stat_directory
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def test_stat_directory(smb_share):
actual = smbclient.stat(smb_share)
assert isinstance(actual, smbclient.SMBStatResult)
assert actual[0] == actual.st_mode
assert actual[1] == actual.st_ino
assert actual[2] == actual.st_dev
assert actual[3] == actual.st_nlink
assert actual[4] == actual.st_uid
assert actual[5] == actual.st_gid
assert actual[6] == actual.st_size
assert actual[7] == actual.st_atime
assert actual[8] == actual.st_mtime
assert actual[9] == actual.st_ctime
assert actual[10] == actual.st_chgtime
assert actual[11] == actual.st_atime_ns
assert actual[12] == actual.st_mtime_ns
assert actual[13] == actual.st_ctime_ns
assert actual[14] == actual.st_chgtime_ns
assert actual[15] == actual.st_file_attributes
assert actual[16] == actual.st_reparse_tag
assert stat.S_ISDIR(actual.st_mode)
assert not stat.S_ISREG(actual.st_mode)
assert not stat.S_ISLNK(actual.st_mode)
assert actual.st_nlink == 1
assert actual.st_gid == 0
assert actual.st_uid == 0
assert actual.st_size == 0
assert actual.st_ctime is not None
assert actual.st_chgtime is not None
assert actual.st_atime is not None
assert actual.st_mtime is not None
assert actual.st_ctime_ns is not None
assert actual.st_chgtime_ns is not None
assert actual.st_atime_ns is not None
assert actual.st_mtime_ns is not None
assert actual.st_file_attributes == FileAttributes.FILE_ATTRIBUTE_DIRECTORY
assert actual.st_reparse_tag == 0
示例9: isfile
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def isfile(path):
"""Test whether a path is a regular file"""
try:
st = os.stat(path)
except os.error:
return False
return stat.S_ISREG(st.st_mode)
# Is a path a directory?
# This follows symbolic links, so both islink() and isdir()
# can be true for the same path on systems that support symlinks
示例10: isfile
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def isfile(self):
return S_ISREG(self._osstatresult.st_mode)
示例11: file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def file(self):
return S_ISREG(self._stat().mode)
示例12: findall
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def findall(self):
"""Find all files under the base and set ``allfiles`` to the absolute
pathnames of files found.
"""
from stat import S_ISREG, S_ISDIR, S_ISLNK
self.allfiles = allfiles = []
root = self.base
stack = [root]
pop = stack.pop
push = stack.append
while stack:
root = pop()
names = os.listdir(root)
for name in names:
fullname = os.path.join(root, name)
# Avoid excess stat calls -- just one will do, thank you!
stat = os.stat(fullname)
mode = stat.st_mode
if S_ISREG(mode):
allfiles.append(fsdecode(fullname))
elif S_ISDIR(mode) and not S_ISLNK(mode):
push(fullname)
示例13: unzip_file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def unzip_file(filename, location, flatten=True):
"""
Unzip the file (with path `filename`) to the destination `location`. All
files are written based on system defaults and umask (i.e. permissions are
not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.
"""
ensure_dir(location)
zipfp = open(filename, 'rb')
try:
zip = zipfile.ZipFile(zipfp, allowZip64=True)
leading = has_leading_dir(zip.namelist()) and flatten
for info in zip.infolist():
name = info.filename
data = zip.read(name)
fn = name
if leading:
fn = split_leading_dir(name)[1]
fn = os.path.join(location, fn)
dir = os.path.dirname(fn)
if fn.endswith('/') or fn.endswith('\\'):
# A directory
ensure_dir(fn)
else:
ensure_dir(dir)
fp = open(fn, 'wb')
try:
fp.write(data)
finally:
fp.close()
mode = info.external_attr >> 16
# if mode and regular file and any execute permissions for
# user/group/world?
if mode and stat.S_ISREG(mode) and mode & 0o111:
# make dest file have execute for user/group/world
# (chmod +x) no-op on windows per python docs
os.chmod(fn, (0o777 - current_umask() | 0o111))
finally:
zipfp.close()
示例14: convert
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def convert(self, value, param, ctx):
rv = value
is_dash = self.file_okay and self.allow_dash and rv in (b'-', '-')
if not is_dash:
if self.resolve_path:
rv = os.path.realpath(rv)
try:
st = os.stat(rv)
except OSError:
if not self.exists:
return self.coerce_path_result(rv)
self.fail('%s "%s" does not exist.' % (
self.path_type,
filename_to_ui(value)
), param, ctx)
if not self.file_okay and stat.S_ISREG(st.st_mode):
self.fail('%s "%s" is a file.' % (
self.path_type,
filename_to_ui(value)
), param, ctx)
if not self.dir_okay and stat.S_ISDIR(st.st_mode):
self.fail('%s "%s" is a directory.' % (
self.path_type,
filename_to_ui(value)
), param, ctx)
if self.writable and not os.access(value, os.W_OK):
self.fail('%s "%s" is not writable.' % (
self.path_type,
filename_to_ui(value)
), param, ctx)
if self.readable and not os.access(value, os.R_OK):
self.fail('%s "%s" is not readable.' % (
self.path_type,
filename_to_ui(value)
), param, ctx)
return self.coerce_path_result(rv)
示例15: linux_copy_mapped_files
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISREG [as 别名]
def linux_copy_mapped_files(self, resolver, volume):
"""Copy all the mapped or opened files to the volume."""
# Build a set of all files.
vma_files = set()
filenames = set()
for x in self._copy_file_to_image(resolver, volume, "/proc/kallsyms"):
yield x
for task in self.session.plugins.pslist().filter_processes():
for vma in task.mm.mmap.walk_list("vm_next"):
vm_file_offset = vma.vm_file.obj_offset
if vm_file_offset in vma_files:
continue
filename = task.get_path(vma.vm_file)
if filename in filenames:
continue
try:
stat_entry = os.stat(filename)
except (OSError, IOError) as e:
self.session.logging.info(
"Skipping %s: %s", filename, e)
continue
mode = stat_entry.st_mode
if stat.S_ISREG(mode):
if stat_entry.st_size <= self.plugin_args.max_file_size:
filenames.add(filename)
vma_files.add(vm_file_offset)
for x in self._copy_file_to_image(
resolver, volume, filename, stat_entry):
yield x
else:
self.session.logging.info(
"Skipping %s: Size larger than %s",
filename, self.plugin_args.max_file_size)