本文整理汇总了Python中stat.S_ISVTX属性的典型用法代码示例。如果您正苦于以下问题:Python stat.S_ISVTX属性的具体用法?Python stat.S_ISVTX怎么用?Python stat.S_ISVTX使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.S_ISVTX属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: find_ext_volume_global_trash
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def find_ext_volume_global_trash(volume_root):
# from [2] Trash directories (1) check for a .Trash dir with the right
# permissions set.
trash_dir = op.join(volume_root, TOPDIR_TRASH)
if not op.exists(trash_dir):
return None
mode = os.lstat(trash_dir).st_mode
# vol/.Trash must be a directory, cannot be a symlink, and must have the
# sticky bit set.
if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX):
return None
trash_dir = op.join(trash_dir, str(uid))
try:
check_create(trash_dir)
except OSError:
return None
return trash_dir
示例2: special_to_letter
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def special_to_letter(mode):
l = ''
ALL_R = (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)
ALL_W = (stat.S_IWUSR | stat.S_IWGRP | stat.S_IWOTH)
if mode & stat.S_ISGID:
l += 'G'
if mode & stat.S_ISUID:
l += 'U'
if mode & stat.S_ISVTX:
l += 'T'
if mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH):
l += 'E'
if ( mode & ALL_R ) == ALL_R:
l += 'R'
if ( mode & ALL_W ) == ALL_W:
l += 'W'
return l
示例3: testStatDirectory_filePermissions
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def testStatDirectory_filePermissions(self):
should_have = (
('some_file', stat.S_IWUSR), # Owner can write.
('tmp', stat.S_IXOTH), # Others can execute.
('tmp', stat.S_ISVTX), # Has sticky bit.
('my_cmd', stat.S_ISGID), # Has set-group-ID bit.
('silly', stat.S_ISUID), # Has set UID bit.
)
should_not_have = (
('some_file', stat.S_IWOTH), # Others can't write.
('block_dev', stat.S_IRGRP), # Group can't read.
('silly', stat.S_IXUSR), # Owner can't execute.
)
entries = self.getStatEntries()
for filename, bit in should_have:
self.assertTrue(entries[filename]['st_mode'] & bit)
for filename, bit in should_not_have:
self.assertFalse(entries[filename]['st_mode'] & bit)
示例4: find_ext_volume_global_trash
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def find_ext_volume_global_trash(volume_root):
# from [2] Trash directories (1) check for a .Trash dir with the right
# permissions set.
trash_dir = op.join(volume_root, TOPDIR_TRASH)
if not op.exists(trash_dir):
return None
mode = os.lstat(trash_dir).st_mode
# vol/.Trash must be a directory, cannot be a symlink, and must have the
# sticky bit set.
if not op.isdir(trash_dir) or op.islink(trash_dir) or not (mode & stat.S_ISVTX):
return None
trash_dir = op.join(trash_dir, text_type(uid).encode('ascii'))
try:
check_create(trash_dir)
except OSError:
return None
return trash_dir
示例5: rm_full_dir
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def rm_full_dir(path, ignore_errors=False):
"""
This function is used to remove a directory and all files and
directories within it (like `rm -rf`).
"""
if os.path.isdir(path):
try:
os.chmod(path, os.stat(path).st_mode | stat.S_IRWXU
& ~stat.S_ISVTX)
except OSError:
pass
f_last = 0
while True:
f_count = 0
for root, d_names, f_names in os.walk(path):
try:
os.chmod(root, os.stat(root).st_mode | stat.S_IRWXU
& ~stat.S_ISVTX)
except OSError:
pass
for fs_name in f_names + d_names:
target = os.path.join(root, fs_name)
try:
os.chmod(target, os.stat(target).st_mode
| stat.S_IRWXU
& ~stat.S_ISVTX)
except OSError:
pass
f_count += 1
f_count += 1
# do this until we get the same count twice, ie. all files we can
# chmod our way into have been found
if f_last == f_count:
break
f_last = f_count
shutil.rmtree(path, ignore_errors)
示例6: insecure_inode
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def insecure_inode(path):
"""This particular inode can be altered by someone other than the owner"""
pathstat = os.stat(path).st_mode
# Directories with a sticky bit are always acceptable.
if os.path.isdir(path) and pathstat & stat.S_ISVTX:
return False
# The path is writable by someone who is not us.
elif pathstat & (stat.S_IWGRP | stat.S_IWOTH):
return True
else:
return False
示例7: is_sticky
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def is_sticky(self):
return True if self.status['st_mode'] & stat.S_ISVTX else False
示例8: make_fsroot
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def make_fsroot(root_dir, emptydirs, stickydirs, mounts):
"""Initializes directory structure for the container in a new root.
"""
_LOGGER.info('Creating fs root in: %s', root_dir)
for directory in sorted(emptydirs):
fs.mkdir_safe(root_dir + directory)
for directory in sorted(stickydirs):
os.chmod(root_dir + directory, 0o777 | stat.S_ISVTX)
# Make shared directories/files readonly to container
reserved = {'/run',
'/sys/fs',
'/var/spool/tickets',
'/var/spool/keytabs',
'/var/spool/tokens'}
for mount, args in mounts.items():
# These are reserved, mounted on memory in make_osroot.
if mount in reserved:
continue
if not args:
fs_linux.mount_bind(
root_dir, mount,
recursive=True, read_only=True
)
else:
fs_linux.mount_bind(root_dir, mount, **args)
示例9: humanUnixAttributes
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def humanUnixAttributes(mode):
"""
Convert a Unix file attributes (or "file mode") to an unicode string.
Original source code:
http://cvs.savannah.gnu.org/viewcvs/coreutils/lib/filemode.c?root=coreutils
>>> humanUnixAttributes(0644)
u'-rw-r--r-- (644)'
>>> humanUnixAttributes(02755)
u'-rwxr-sr-x (2755)'
"""
def ftypelet(mode):
if stat.S_ISREG (mode) or not stat.S_IFMT(mode):
return '-'
if stat.S_ISBLK (mode): return 'b'
if stat.S_ISCHR (mode): return 'c'
if stat.S_ISDIR (mode): return 'd'
if stat.S_ISFIFO(mode): return 'p'
if stat.S_ISLNK (mode): return 'l'
if stat.S_ISSOCK(mode): return 's'
return '?'
chars = [ ftypelet(mode), 'r', 'w', 'x', 'r', 'w', 'x', 'r', 'w', 'x' ]
for i in xrange(1, 10):
if not mode & 1 << 9 - i:
chars[i] = '-'
if mode & stat.S_ISUID:
if chars[3] != 'x':
chars[3] = 'S'
else:
chars[3] = 's'
if mode & stat.S_ISGID:
if chars[6] != 'x':
chars[6] = 'S'
else:
chars[6] = 's'
if mode & stat.S_ISVTX:
if chars[9] != 'x':
chars[9] = 'T'
else:
chars[9] = 't'
return u"%s (%o)" % (''.join(chars), mode)
示例10: calc_mode
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def calc_mode(
sticky=False,
isuid=True,
isgid=True,
type=stat.S_IFREG,
owner_read=True,
owner_write=True,
owner_exec=True,
group_read=True,
group_write=True,
group_exec=True,
other_read=True,
other_write=True,
other_exec=True,
):
"""helper function to calculate the mode bits of a file."""
mode = 0
if owner_read:
mode |= stat.S_IRUSR
if owner_write:
mode |= stat.S_IWUSR
if owner_exec:
mode |= stat.S_IXUSR
if group_read:
mode |= stat.S_IRGRP
if group_write:
mode |= stat.S_IWGRP
if group_exec:
mode |= stat.S_IXGRP
if other_read:
mode |= stat.S_IROTH
if other_write:
mode |= stat.S_IWOTH
if other_exec:
mode |= stat.S_IXOTH
if sticky:
mode |= stat.S_ISVTX
if isuid:
mode |= stat.ST_UID
if isgid:
mode |= stat.ST_GID
mode |= type
return mode
示例11: __str__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def __str__(self):
"create a unix-style long description of the file (like ls -l)"
if self.st_mode is not None:
kind = stat.S_IFMT(self.st_mode)
if kind == stat.S_IFIFO:
ks = 'p'
elif kind == stat.S_IFCHR:
ks = 'c'
elif kind == stat.S_IFDIR:
ks = 'd'
elif kind == stat.S_IFBLK:
ks = 'b'
elif kind == stat.S_IFREG:
ks = '-'
elif kind == stat.S_IFLNK:
ks = 'l'
elif kind == stat.S_IFSOCK:
ks = 's'
else:
ks = '?'
ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID)
ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID)
ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True)
else:
ks = '?---------'
# compute display date
if (self.st_mtime is None) or (self.st_mtime == 0xffffffffL):
# shouldn't really happen
datestr = '(unknown date)'
else:
if abs(time.time() - self.st_mtime) > 15552000:
# (15552000 = 6 months)
datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime))
else:
datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime))
filename = getattr(self, 'filename', '?')
# not all servers support uid/gid
uid = self.st_uid
gid = self.st_gid
if uid is None:
uid = 0
if gid is None:
gid = 0
return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, self.st_size, datestr, filename)
示例12: __str__
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_ISVTX [as 别名]
def __str__(self):
"""create a unix-style long description of the file (like ls -l)"""
if self.st_mode is not None:
kind = stat.S_IFMT(self.st_mode)
if kind == stat.S_IFIFO:
ks = 'p'
elif kind == stat.S_IFCHR:
ks = 'c'
elif kind == stat.S_IFDIR:
ks = 'd'
elif kind == stat.S_IFBLK:
ks = 'b'
elif kind == stat.S_IFREG:
ks = '-'
elif kind == stat.S_IFLNK:
ks = 'l'
elif kind == stat.S_IFSOCK:
ks = 's'
else:
ks = '?'
ks += self._rwx((self.st_mode & o700) >> 6, self.st_mode & stat.S_ISUID)
ks += self._rwx((self.st_mode & o70) >> 3, self.st_mode & stat.S_ISGID)
ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True)
else:
ks = '?---------'
# compute display date
if (self.st_mtime is None) or (self.st_mtime == xffffffff):
# shouldn't really happen
datestr = '(unknown date)'
else:
if abs(time.time() - self.st_mtime) > 15552000:
# (15552000 = 6 months)
datestr = time.strftime('%d %b %Y', time.localtime(self.st_mtime))
else:
datestr = time.strftime('%d %b %H:%M', time.localtime(self.st_mtime))
filename = getattr(self, 'filename', '?')
# not all servers support uid/gid
uid = self.st_uid
gid = self.st_gid
size = self.st_size
if uid is None:
uid = 0
if gid is None:
gid = 0
if size is None:
size = 0
return '%s 1 %-8d %-8d %8d %-12s %s' % (ks, uid, gid, size, datestr, filename)