Python stat.S_IRWXO Examples
The following are 30
code examples of stat.S_IRWXO().
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: 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 #3
Source File: test_shutil.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
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)
Example #4
Source File: fwaudit.py From fwaudit with GNU General Public License v2.0 | 6 votes |
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)
Example #5
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 #6
Source File: test_shutil.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
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)
Example #7
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 #8
Source File: checks.py From Inboxen with GNU Affero General Public License v3.0 | 6 votes |
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 []
Example #9
Source File: migrations_test.py From python-spanner-orm with Apache License 2.0 | 6 votes |
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)
Example #10
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 #11
Source File: test_shutil.py From ironpython3 with Apache License 2.0 | 6 votes |
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)
Example #12
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 #13
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 #14
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 #15
Source File: conan_client.py From hooks with MIT License | 5 votes |
def tearDownClass(cls): os.chdir(cls._old_cwd) def handleRemoveReadonly(func, path, exc): import errno, stat excvalue = exc[1] if func in (os.rmdir, os.remove, os.unlink) and excvalue.errno == errno.EACCES: os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) # 0777 func(path) else: raise Exception("Failed to remove '{}'".format(path)) shutil.rmtree(cls._working_dir, onerror=handleRemoveReadonly)
Example #16
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
Example #17
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 #18
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 #19
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 #20
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 #21
Source File: test_shutil.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_copystat_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') dst_link = os.path.join(tmp_dir, 'qux') write_file(src, 'foo') src_stat = os.stat(src) os.utime(src, (src_stat.st_atime, src_stat.st_mtime - 42.0)) # ensure different mtimes write_file(dst, 'bar') self.assertNotEqual(os.stat(src).st_mtime, os.stat(dst).st_mtime) os.symlink(src, src_link) os.symlink(dst, dst_link) if hasattr(os, 'lchmod'): os.lchmod(src_link, stat.S_IRWXO) if hasattr(os, 'lchflags') and hasattr(stat, 'UF_NODUMP'): os.lchflags(src_link, stat.UF_NODUMP) src_link_stat = os.lstat(src_link) # follow if hasattr(os, 'lchmod'): shutil.copystat(src_link, dst_link, follow_symlinks=True) self.assertNotEqual(src_link_stat.st_mode, os.stat(dst).st_mode) # don't follow shutil.copystat(src_link, dst_link, follow_symlinks=False) dst_link_stat = os.lstat(dst_link) if os.utime in os.supports_follow_symlinks: for attr in 'st_atime', 'st_mtime': # The modification times may be truncated in the new file. self.assertLessEqual(getattr(src_link_stat, attr), getattr(dst_link_stat, attr) + 1) if hasattr(os, 'lchmod'): self.assertEqual(src_link_stat.st_mode, dst_link_stat.st_mode) if hasattr(os, 'lchflags') and hasattr(src_link_stat, 'st_flags'): self.assertEqual(src_link_stat.st_flags, dst_link_stat.st_flags) # tell to follow but dst is not a link shutil.copystat(src_link, dst, follow_symlinks=False) self.assertTrue(abs(os.stat(src).st_mtime - os.stat(dst).st_mtime) < 00000.1)
Example #22
Source File: test_shutil.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_copymode_symlink_to_symlink(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') dst_link = os.path.join(tmp_dir, 'quux') write_file(src, 'foo') write_file(dst, 'foo') os.symlink(src, src_link) os.symlink(dst, dst_link) os.chmod(src, stat.S_IRWXU|stat.S_IRWXG) os.chmod(dst, stat.S_IRWXU) os.lchmod(src_link, stat.S_IRWXO|stat.S_IRWXG) # link to link os.lchmod(dst_link, stat.S_IRWXO) shutil.copymode(src_link, dst_link, follow_symlinks=False) self.assertEqual(os.lstat(src_link).st_mode, os.lstat(dst_link).st_mode) self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode) # src link - use chmod os.lchmod(dst_link, stat.S_IRWXO) shutil.copymode(src_link, dst, follow_symlinks=False) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) # dst link - use chmod os.lchmod(dst_link, stat.S_IRWXO) shutil.copymode(src, dst_link, follow_symlinks=False) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
Example #23
Source File: test_shutil.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def test_copymode_follow_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') dst_link = os.path.join(tmp_dir, 'quux') write_file(src, 'foo') write_file(dst, 'foo') os.symlink(src, src_link) os.symlink(dst, dst_link) os.chmod(src, stat.S_IRWXU|stat.S_IRWXG) # file to file os.chmod(dst, stat.S_IRWXO) self.assertNotEqual(os.stat(src).st_mode, os.stat(dst).st_mode) shutil.copymode(src, dst) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) # On Windows, os.chmod does not follow symlinks (issue #15411) if os.name != 'nt': # follow src link os.chmod(dst, stat.S_IRWXO) shutil.copymode(src_link, dst) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) # follow dst link os.chmod(dst, stat.S_IRWXO) shutil.copymode(src, dst_link) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode) # follow both links os.chmod(dst, stat.S_IRWXO) shutil.copymode(src_link, dst_link) self.assertEqual(os.stat(src).st_mode, os.stat(dst).st_mode)
Example #24
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 #25
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 #26
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 #27
Source File: test_stat.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
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)
Example #28
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 #29
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 #30
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