Python stat.S_IRWXG Examples
The following are 30
code examples of stat.S_IRWXG().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
stat
, or try the search function
.
Example #1
Source File: comicscan.py From gazee with GNU General Public License v3.0 | 7 votes |
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
Example #2
Source File: actions.py From st2 with Apache License 2.0 | 6 votes |
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)
Example #3
Source File: socket.py From nano-dpow with MIT License | 6 votes |
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
Example #4
Source File: password_ipc.py From backintime with GNU General Public License v2.0 | 6 votes |
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
Example #5
Source File: lib.py From black with MIT License | 6 votes |
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
Example #6
Source File: netrc.py From code with MIT License | 6 votes |
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)
Example #7
Source File: Cluster.py From CGATPipelines with MIT License | 6 votes |
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
Example #8
Source File: comicscan.py From gazee with GNU General Public License v3.0 | 6 votes |
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.
Example #9
Source File: interface.py From pytest-sftpserver with MIT License | 6 votes |
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
Example #10
Source File: kodipathtools.py From script.service.kodi.callbacks with GNU General Public License v3.0 | 5 votes |
def setPathRW(path): path = translatepath(path) try: os.chmod(path, os.stat(path).st_mode | stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) except OSError: pass
Example #11
Source File: pack_management.py From st2 with Apache License 2.0 | 5 votes |
def apply_pack_permissions(pack_path): """ Recursively apply permission 775 to pack and its contents. """ # These mask is same as mode = 775 mode = stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH os.chmod(pack_path, mode) # Yuck! Since os.chmod does not support chmod -R walk manually. for root, dirs, files in os.walk(pack_path): for d in dirs: os.chmod(os.path.join(root, d), mode) for f in files: os.chmod(os.path.join(root, f), mode)
Example #12
Source File: test_snapshots.py From backintime with GNU General Public License v2.0 | 5 votes |
def test_collectPermission(self): # force permissions because different distributions will have different umask os.chmod(self.testDirFullPath, stat.S_IRWXU | stat.S_IRWXG | stat.S_IROTH | stat.S_IXOTH) os.chmod(self.testFileFullPath, stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IROTH) d = snapshots.FileInfoDict() testDir = self.testDirFullPath.encode() testFile = self.testFileFullPath.encode() self.sn.collectPermission(d, testDir) self.sn.collectPermission(d, testFile) self.assertIn(testDir, d) self.assertIn(testFile, d) self.assertTupleEqual(d[testDir], (16893, CURRENTUSER.encode(), CURRENTGROUP.encode())) self.assertTupleEqual(d[testFile], (33204, CURRENTUSER.encode(), CURRENTGROUP.encode()))
Example #13
Source File: test_adbapi.py From python-for-android with Apache License 2.0 | 5 votes |
def startDB(self): import kinterbasdb self.DB_NAME = os.path.join(self.DB_DIR, DBTestConnector.DB_NAME) os.chmod(self.DB_DIR, stat.S_IRWXU + stat.S_IRWXG + stat.S_IRWXO) sql = 'create database "%s" user "%s" password "%s"' sql %= (self.DB_NAME, self.DB_USER, self.DB_PASS); conn = kinterbasdb.create_database(sql) conn.close()
Example #14
Source File: regrtest.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #15
Source File: private_key.py From raiden-contracts with MIT License | 5 votes |
def check_permission_safety(path: Path) -> bool: """Check if the file at the given path is safe to use as a state file. This checks that group and others have no permissions on the file and that the current user is the owner. """ f_stats = os.stat(path) return (f_stats.st_mode & (stat.S_IRWXG | stat.S_IRWXO)) == 0 and f_stats.st_uid == os.getuid()
Example #16
Source File: views.py From cua-arbiter with GNU General Public License v2.0 | 5 votes |
def get_caseobj(self): case_path = os.getenv("CASEPATH") json_obj = json.loads(self.body) if Git_Info.objects.count() > 0: info = Git_Info.objects.get() info.git_url = json_obj.get('url') info.user_name = json_obj.get("git_username") info.password = json_obj.get("git_password") info.save() def set_rw(operation, name, exc): os.chmod(name, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) os.remove(name) return True shutil.rmtree('../arbiter-cases', onerror=set_rw) else: Git_Info.objects.create(user_name=json_obj.get("git_username"), password=json_obj.get("git_password"), git_url=json_obj.get('url')) repo = git.Repo.clone_from(json_obj.get('url'), '../arbiter-cases/' + case_path.split('/')[0], branch='master') response_data = {'success': True} if Case_List.objects.count() > 0: case_list = Case_List.objects.get() case_list.name = "arbiter_cases" case_list.data = CaseList.getList() case_list.save() else: Case_List.objects.create(name="arbiter_cases", data=CaseList.getList()) return JsonResponse(response_data) # 下列接口需要登录验证
Example #17
Source File: kodipathtools.py From script.service.kodi.callbacks with GNU General Public License v3.0 | 5 votes |
def setPathExecuteRW(path): path = translatepath(path) try: os.chmod(path, os.stat( path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) except OSError: pass
Example #18
Source File: cluster.py From cgat-core with MIT License | 5 votes |
def set_drmaa_job_paths(self, 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 stdout_path, stderr_path
Example #19
Source File: test_adbapi.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def startDB(self): import kinterbasdb self.DB_NAME = os.path.join(self.DB_DIR, DBTestConnector.DB_NAME) os.chmod(self.DB_DIR, stat.S_IRWXU + stat.S_IRWXG + stat.S_IRWXO) sql = 'create database "%s" user "%s" password "%s"' sql %= (self.DB_NAME, self.DB_USER, self.DB_PASS); conn = kinterbasdb.create_database(sql) conn.close()
Example #20
Source File: regrtest.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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 (test_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))
Example #21
Source File: fileoperations.py From aws-elastic-beanstalk-cli with Apache License 2.0 | 5 votes |
def set_all_unrestricted_permissions(location): """ Set permissions so that user, group, and others all have read, write and execute permissions (chmod 777). :param location: Full location of either a folder or a location """ os.chmod(location, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
Example #22
Source File: runmayatests.py From cmt with MIT License | 5 votes |
def remove_read_only(func, path, exc): """Called by shutil.rmtree when it encounters a readonly file. :param func: :param path: :param exc: """ 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))
Example #23
Source File: connect_utils.py From asyncpg with Apache License 2.0 | 5 votes |
def _read_password_file(passfile: pathlib.Path) \ -> typing.List[typing.Tuple[str, ...]]: passtab = [] try: if not passfile.exists(): return [] if not passfile.is_file(): warnings.warn( 'password file {!r} is not a plain file'.format(passfile)) return [] if _system != 'Windows': if passfile.stat().st_mode & (stat.S_IRWXG | stat.S_IRWXO): warnings.warn( 'password file {!r} has group or world access; ' 'permissions should be u=rw (0600) or less'.format( passfile)) return [] with passfile.open('rt') as f: for line in f: line = line.strip() if not line or line.startswith('#'): # Skip empty lines and comments. continue # Backslash escapes both itself and the colon, # which is a record separator. line = line.replace(R'\\', '\n') passtab.append(tuple( p.replace('\n', R'\\') for p in re.split(r'(?<!\\):', line, maxsplit=4) )) except IOError: pass return passtab
Example #24
Source File: test_xdg.py From http-prompt with MIT License | 5 votes |
def test_get_app_data_home(self): path = xdg.get_data_dir() expected_path = os.path.join(os.environ[self.homes['data']], 'http-prompt') self.assertEqual(path, expected_path) self.assertTrue(os.path.exists(path)) if sys.platform != 'win32': # Make sure permission for the directory is 700 mask = stat.S_IMODE(os.stat(path).st_mode) self.assertTrue(mask & stat.S_IRWXU) self.assertFalse(mask & stat.S_IRWXG) self.assertFalse(mask & stat.S_IRWXO)
Example #25
Source File: test_xdg.py From http-prompt with MIT License | 5 votes |
def test_get_app_config_home(self): path = xdg.get_config_dir() expected_path = os.path.join(os.environ[self.homes['config']], 'http-prompt') self.assertEqual(path, expected_path) self.assertTrue(os.path.exists(path)) if sys.platform != 'win32': # Make sure permission for the directory is 700 mask = stat.S_IMODE(os.stat(path).st_mode) self.assertTrue(mask & stat.S_IRWXU) self.assertFalse(mask & stat.S_IRWXG) self.assertFalse(mask & stat.S_IRWXO)
Example #26
Source File: runtime.py From storlets with Apache License 2.0 | 5 votes |
def create_host_pipe_dir(self): path = self.host_pipe_dir if not os.path.exists(path): os.makedirs(path) # 0777 should be 0700 when we get user namespaces in Docker os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) return path
Example #27
Source File: runastrodriz.py From drizzlepac with BSD 3-Clause "New" or "Revised" License | 5 votes |
def handle_remove_readonly(func, path, exc): 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 # Functions to support execution from the shell.
Example #28
Source File: runtest.py From android_universal with MIT License | 5 votes |
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)
Example #29
Source File: test_nbgrader_submit.py From nbgrader with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_submit_readonly(self, exchange, cache, course_dir): self._release_and_fetch("ps1", exchange, cache, course_dir) os.chmod(join("ps1", "p1.ipynb"), stat.S_IRUSR) self._submit("ps1", exchange, cache) filename, = os.listdir(join(exchange, "abc101", "inbound")) perms = os.stat(join(exchange, "abc101", "inbound", filename, "p1.ipynb")).st_mode perms = str(oct(perms & (stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)))[-3:] assert int(perms[0]) >= 4 assert int(perms[1]) == 4 assert int(perms[2]) == 4
Example #30
Source File: create.py From workload-automation with Apache License 2.0 | 5 votes |
def create_uiauto_project(path, name): package_name = 'com.arm.wa.uiauto.' + name.lower() copy_tree(os.path.join(TEMPLATES_DIR, 'uiauto', 'uiauto_workload_template'), path) manifest_path = os.path.join(path, 'app', 'src', 'main') mainifest = os.path.join(_d(manifest_path), 'AndroidManifest.xml') with open(mainifest, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'uiauto_AndroidManifest.xml'), {'package_name': package_name})) build_gradle_path = os.path.join(path, 'app') build_gradle = os.path.join(_d(build_gradle_path), 'build.gradle') with open(build_gradle, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'uiauto_build.gradle'), {'package_name': package_name})) build_script = os.path.join(path, 'build.sh') with open(build_script, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'uiauto_build_script'), {'package_name': package_name})) os.chmod(build_script, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) source_file = _f(os.path.join(path, 'app', 'src', 'main', 'java', os.sep.join(package_name.split('.')[:-1]), 'UiAutomation.java')) with open(source_file, 'w') as wfh: wfh.write(render_template(os.path.join('uiauto', 'UiAutomation.java'), {'name': name, 'package_name': package_name})) # Mapping of workload types to their corresponding creation method