本文整理汇总了Python中stat.S_IRWXG属性的典型用法代码示例。如果您正苦于以下问题:Python stat.S_IRWXG属性的具体用法?Python stat.S_IRWXG怎么用?Python stat.S_IRWXG使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类stat
的用法示例。
在下文中一共展示了stat.S_IRWXG属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build_unpack_comic
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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
示例2: user_unpack_comic
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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.
示例3: stat
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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
示例4: _write_data_file
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [as 别名]
def _write_data_file(self, pack_ref, file_path, content):
"""
Write data file on disk.
"""
# Throw if pack directory doesn't exist
pack_base_path = get_pack_base_path(pack_name=pack_ref)
if not os.path.isdir(pack_base_path):
raise ValueError('Directory for pack "%s" doesn\'t exist' % (pack_ref))
# Create pack sub-directory tree if it doesn't exist
directory = os.path.dirname(file_path)
if not os.path.isdir(directory):
# NOTE: We apply same permission bits as we do on pack install. If we don't do that,
# st2api won't be able to write to pack sub-directory
mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH
os.makedirs(directory, mode)
with open(file_path, 'w') as fp:
fp.write(content)
示例5: get_socket
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [as 别名]
def get_socket(path: str):
# Adapted from https://github.com/aio-libs/aiohttp/issues/4155#issuecomment-539640591
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
try:
if stat.S_ISSOCK(os.stat(path).st_mode):
os.remove(path)
except FileNotFoundError:
pass
try:
sock.bind(path)
except OSError as exc:
sock.close()
if exc.errno == errno.EADDRINUSE:
msg = f'Address {path!r} is already in use'
raise OSError(errno.EADDRINUSE, msg) from None
else:
raise
except:
sock.close()
raise
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH)
return sock
示例6: isFifo
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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_IRWXG [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_IRWXG [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: setDrmaaJobPaths
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [as 别名]
def setDrmaaJobPaths(job_template, job_path):
'''Adds the job_path, stdout_path and stderr_paths
to the job_template.
'''
job_path = os.path.abspath(job_path)
os.chmod(job_path, stat.S_IRWXG | stat.S_IRWXU)
stdout_path = job_path + ".stdout"
stderr_path = job_path + ".stderr"
job_template.remoteCommand = job_path
job_template.outputPath = ":" + stdout_path
job_template.errorPath = ":" + stderr_path
return job_template, stdout_path, stderr_path
示例10: cleanup_test_droppings
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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)
示例11: _get_all
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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)
示例12: cleanup_test_droppings
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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))
示例13: test_mode
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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)
示例14: remove_read_only
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [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))
示例15: remove_read_only
# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRWXG [as 别名]
def remove_read_only(func, path, exc):
"If we can't remove a file/directory, change permissions and try again."
if func in (os.rmdir, os.remove) and exc[1].errno == errno.EACCES:
# change the file to be readable,writable,executable: 0777
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
func(path) # try again