本文整理汇总了Python中stat.S_IRWXO属性的典型用法代码示例。如果您正苦于以下问题:Python stat.S_IRWXO属性的具体用法?Python stat.S_IRWXO怎么用?Python stat.S_IRWXO使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.S_IRWXO属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_sudo_user_group_mode
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def get_sudo_user_group_mode():
'''TBW'''
# XXX only need uid, gid, and file mode for sudo case...
new_uid = int(os.environ.get('SUDO_UID'))
if new_uid is None:
error('Unable to obtain SUDO_UID')
return False
#debug('new UID via SUDO_UID: ' + str(new_uid))
new_gid = int(os.environ.get('SUDO_GID'))
if new_gid is None:
error('Unable to obtain SUDO_GID')
return False
#debug('new GID via SUDO_GID: ' + str(new_gid))
# new_dir_mode = (stat.S_IRUSR|stat.S_IWUSR|stat.S_IRGRP|stat.S_IWGRP|stat.S_IROTH|stat.S_IWOTH)
rwx_mode = (stat.S_IRWXU|stat.S_IRWXG|stat.S_IRWXO)
new_dir_mode = rwx_mode
#debug('new dir mode: ' + str(new_dir_mode))
return (new_dir_mode, new_uid, new_gid)
示例2: test_copy_symlinks
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def test_copy_symlinks(self):
tmp_dir = self.mkdtemp()
src = os.path.join(tmp_dir, 'foo')
dst = os.path.join(tmp_dir, 'bar')
src_link = os.path.join(tmp_dir, 'baz')
write_file(src, 'foo')
os.symlink(src, src_link)
if hasattr(os, 'lchmod'):
os.lchmod(src_link, stat.S_IRWXU | stat.S_IRWXO)
# don't follow
shutil.copy(src_link, dst, follow_symlinks=True)
self.assertFalse(os.path.islink(dst))
self.assertEqual(read_file(src), read_file(dst))
os.remove(dst)
# follow
shutil.copy(src_link, dst, follow_symlinks=False)
self.assertTrue(os.path.islink(dst))
self.assertEqual(os.readlink(dst), os.readlink(src_link))
if hasattr(os, 'lchmod'):
self.assertEqual(os.lstat(src_link).st_mode,
os.lstat(dst).st_mode)
示例3: build_unpack_comic
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def build_unpack_comic(self, comic_path):
logging.info("%s unpack requested" % comic_path)
for root, dirs, files in os.walk(os.path.join(gazee.TEMP_DIR, "build"), topdown=False):
for f in files:
os.chmod(os.path.join(root, f), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777
os.remove(os.path.join(root, f))
for root, dirs, files in os.walk(os.path.join(gazee.TEMP_DIR, "build"), topdown=False):
for d in dirs:
os.chmod(os.path.join(root, d), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777
os.rmdir(os.path.join(root, d))
if comic_path.endswith(".cbr"):
opened_rar = rarfile.RarFile(comic_path)
opened_rar.extractall(os.path.join(gazee.TEMP_DIR, "build"))
elif comic_path.endswith(".cbz"):
opened_zip = zipfile.ZipFile(comic_path)
opened_zip.extractall(os.path.join(gazee.TEMP_DIR, "build"))
return
示例4: user_unpack_comic
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def user_unpack_comic(self, comic_path, user):
logging.info("%s unpack requested" % comic_path)
for root, dirs, files in os.walk(os.path.join(gazee.TEMP_DIR, user), topdown=False):
for f in files:
os.chmod(os.path.join(root, f), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777
os.remove(os.path.join(root, f))
for root, dirs, files in os.walk(os.path.join(gazee.TEMP_DIR, user), topdown=False):
for d in dirs:
os.chmod(os.path.join(root, d), stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777
os.rmdir(os.path.join(root, d))
if comic_path.endswith(".cbr"):
opened_rar = rarfile.RarFile(comic_path)
opened_rar.extractall(os.path.join(gazee.TEMP_DIR, user))
elif comic_path.endswith(".cbz"):
opened_zip = zipfile.ZipFile(comic_path)
opened_zip.extractall(os.path.join(gazee.TEMP_DIR, user))
return
# This method will return a list of .jpg files in their numberical order to be fed into the reading view.
示例5: stat
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def stat(self):
if self.content_provider.get(self.path) is None:
return SFTP_NO_SUCH_FILE
mtime = calendar.timegm(datetime.now().timetuple())
sftp_attrs = SFTPAttributes()
sftp_attrs.st_size = self.content_provider.get_size(self.path)
sftp_attrs.st_uid = 0
sftp_attrs.st_gid = 0
sftp_attrs.st_mode = (
stat.S_IRWXO
| stat.S_IRWXG
| stat.S_IRWXU
| (stat.S_IFDIR if self.content_provider.is_dir(self.path) else stat.S_IFREG)
)
sftp_attrs.st_atime = mtime
sftp_attrs.st_mtime = mtime
sftp_attrs.filename = posixpath.basename(self.path)
return sftp_attrs
示例6: isFifo
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def isFifo(self):
"""
make sure file is still a FIFO and has correct permissions
"""
try:
s = os.stat(self.fifo)
except OSError:
return False
if not s.st_uid == os.getuid():
logger.error('%s is not owned by user' % self.fifo, self)
return False
mode = s.st_mode
if not stat.S_ISFIFO(mode):
logger.error('%s is not a FIFO' % self.fifo, self)
return False
forbidden_perm = stat.S_IXUSR + stat.S_IRWXG + stat.S_IRWXO
if mode & forbidden_perm > 0:
logger.error('%s has wrong permissions' % self.fifo, self)
return False
return True
示例7: handle_PermissionError
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def handle_PermissionError(
func: Callable, path: Path, exc: Tuple[Any, Any, Any]
) -> None:
"""
Handle PermissionError during shutil.rmtree.
This checks if the erroring function is either 'os.rmdir' or 'os.unlink', and that
the error was EACCES (i.e. Permission denied). If true, the path is set writable,
readable, and executable by everyone. Finally, it tries the error causing delete
operation again.
If the check is false, then the original error will be reraised as this function
can't handle it.
"""
excvalue = exc[1]
LOG.debug(f"Handling {excvalue} from {func.__name__}... ")
if func in (os.rmdir, os.unlink) and excvalue.errno == errno.EACCES:
LOG.debug(f"Setting {path} writable, readable, and executable by everyone... ")
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # chmod 0777
func(path) # Try the error causing delete operation again
else:
raise
示例8: check_owner
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def check_owner(fp):
if os.name != 'posix':
return
prop = os.fstat(fp.fileno())
if prop.st_uid != os.getuid():
import pwd
try:
fowner = pwd.getpwuid(prop.st_uid)[0]
except KeyError:
fowner = 'uid %s' % prop.st_uid
try:
user = pwd.getpwuid(os.getuid())[0]
except KeyError:
user = 'uid %s' % os.getuid()
raise NetrcParseError(
("~/.netrc file owner (%s) does not match"
" current user (%s)") % (fowner, user),
file, lexer.lineno)
if prop.st_mode & (stat.S_IRWXG | stat.S_IRWXO):
raise NetrcParseError(
"~/.netrc access too permissive: access"
" permissions must restrict access to only"
" the owner", file, lexer.lineno)
示例9: config_permissions_check
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def config_permissions_check(app_configs, **kwargs):
"""Check that our chosen settings file cannot be interacted with by other
users"""
if settings.CONFIG_PATH == "":
return []
try:
mode = os.stat(settings.CONFIG_PATH).st_mode
except OSError:
raise exceptions.ImproperlyConfigured("Could not stat {}".format(settings.CONFIG_PATH))
if mode & stat.S_IRWXO != 0:
return [
Error(PERMISSION_ERROR_MSG)
]
else:
return []
示例10: test_generate
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def test_generate(self):
testdata_filename = os.path.join(os.path.dirname(__file__),
'migrations')
shutil.rmtree(self.TEST_MIGRATIONS_DIR)
shutil.copytree(testdata_filename, self.TEST_MIGRATIONS_DIR)
os.chmod(self.TEST_MIGRATIONS_DIR,
stat.S_IRWXO | stat.S_IRWXU)
for f in os.listdir(self.TEST_MIGRATIONS_DIR):
file_path = os.path.join(self.TEST_MIGRATIONS_DIR, f)
if not os.path.isdir(file_path):
os.chmod(file_path,
stat.S_IROTH | stat.S_IWOTH | stat.S_IRUSR | stat.S_IWUSR)
manager = migration_manager.MigrationManager(self.TEST_MIGRATIONS_DIR)
path = manager.generate('test migration')
try:
migration_ = manager._migration_from_file(path)
self.assertIsNotNone(migration_.migration_id)
self.assertIsNotNone(migration_.prev_migration_id)
self.assertIsInstance(migration_.upgrade(), update.NoUpdate)
self.assertIsInstance(migration_.downgrade(), update.NoUpdate)
finally:
shutil.rmtree(self.TEST_MIGRATIONS_DIR)
示例11: cleanup_test_droppings
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def cleanup_test_droppings(testname, verbose):
import shutil
import stat
import gc
# First kill any dangling references to open files etc.
# This can also issue some ResourceWarnings which would otherwise get
# triggered during the following test run, and possibly produce failures.
gc.collect()
# Try to clean up junk commonly left behind. While tests shouldn't leave
# any files or directories behind, when a test fails that can be tedious
# for it to arrange. The consequences can be especially nasty on Windows,
# since if a test leaves a file open, it cannot be deleted by name (while
# there's nothing we can do about that here either, we can display the
# name of the offending test, which is a real help).
for name in (support.TESTFN,
"db_home",
):
if not os.path.exists(name):
continue
if os.path.isdir(name):
kind, nuker = "directory", shutil.rmtree
elif os.path.isfile(name):
kind, nuker = "file", os.unlink
else:
raise SystemError("os.path says %r exists but is neither "
"directory nor file" % name)
if verbose:
print("%r left behind %s %r" % (testname, kind, name))
try:
# if we have chmod, fix possible permissions problems
# that might prevent cleanup
if (hasattr(os, 'chmod')):
os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
nuker(name)
except Exception as msg:
print(("%r left behind %s %r and it couldn't be "
"removed: %s" % (testname, kind, name, msg)), file=sys.stderr)
示例12: _get_all
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def _get_all(self, empty_on_file_not_found=True) -> dict:
if not self._path.exists():
if empty_on_file_not_found:
return {}
raise FileNotFoundError(self._path)
mode = self._path.stat().st_mode
if (mode & stat.S_IRWXG) or (mode & stat.S_IRWXO):
raise PermissionError(
"Refresh token file {p} is readable by others: st_mode {a:o} (expected permissions: {e:o}).".format(
p=self._path, a=mode, e=self._PERMS)
)
with self._path.open("r", encoding="utf8") as f:
log.info("Using refresh tokens from {p}".format(p=self._path))
return json.load(f)
示例13: cleanup_test_droppings
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def cleanup_test_droppings(testname, verbose):
import stat
import gc
# First kill any dangling references to open files etc.
gc.collect()
# Try to clean up junk commonly left behind. While tests shouldn't leave
# any files or directories behind, when a test fails that can be tedious
# for it to arrange. The consequences can be especially nasty on Windows,
# since if a test leaves a file open, it cannot be deleted by name (while
# there's nothing we can do about that here either, we can display the
# name of the offending test, which is a real help).
for name in (support.TESTFN,
"db_home",
):
if not os.path.exists(name):
continue
if os.path.isdir(name):
kind, nuker = "directory", shutil.rmtree
elif os.path.isfile(name):
kind, nuker = "file", os.unlink
else:
raise SystemError("os.path says %r exists but is neither "
"directory nor file" % name)
if verbose:
print "%r left behind %s %r" % (testname, kind, name)
try:
# if we have chmod, fix possible permissions problems
# that might prevent cleanup
if (hasattr(os, 'chmod')):
os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
nuker(name)
except Exception, msg:
print >> sys.stderr, ("%r left behind %s %r and it couldn't be "
"removed: %s" % (testname, kind, name, msg))
示例14: test_mode
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def test_mode(self):
with open(TESTFN, 'w'):
pass
if os.name == 'posix':
os.chmod(TESTFN, 0o700)
st_mode = self.get_mode()
self.assertS_IS("REG", st_mode)
self.assertEqual(stat.S_IMODE(st_mode),
stat.S_IRWXU)
os.chmod(TESTFN, 0o070)
st_mode = self.get_mode()
self.assertS_IS("REG", st_mode)
self.assertEqual(stat.S_IMODE(st_mode),
stat.S_IRWXG)
os.chmod(TESTFN, 0o007)
st_mode = self.get_mode()
self.assertS_IS("REG", st_mode)
self.assertEqual(stat.S_IMODE(st_mode),
stat.S_IRWXO)
os.chmod(TESTFN, 0o444)
st_mode = self.get_mode()
self.assertS_IS("REG", st_mode)
self.assertEqual(stat.S_IMODE(st_mode), 0o444)
else:
os.chmod(TESTFN, 0o700)
st_mode = self.get_mode()
self.assertS_IS("REG", st_mode)
self.assertEqual(stat.S_IFMT(st_mode),
stat.S_IFREG)
示例15: remove_read_only
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXO [as 别名]
def remove_read_only(func, path, exc):
""" Called by shutil.rmtree when it encounters a readonly file. """
excvalue = exc[1]
if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES:
os.chmod(path, stat.S_IRWXU| stat.S_IRWXG| stat.S_IRWXO) # 0777
func(path)
else:
raise RuntimeError('Could not remove {0}'.format(path))