Python stat.S_IXUSR Examples
The following are 30
code examples of stat.S_IXUSR().
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: ssm.py From aegea with Apache License 2.0 | 10 votes |
def ensure_session_manager_plugin(): session_manager_dir = os.path.join(config.user_config_dir, "bin") PATH = os.environ.get("PATH", "") + ":" + session_manager_dir if shutil.which("session-manager-plugin", path=PATH): subprocess.check_call(["session-manager-plugin"], env=dict(os.environ, PATH=PATH)) else: os.makedirs(session_manager_dir, exist_ok=True) target_path = os.path.join(session_manager_dir, "session-manager-plugin") if platform.system() == "Darwin": download_session_manager_plugin_macos(target_path=target_path) elif platform.linux_distribution()[0] == "Ubuntu": download_session_manager_plugin_linux(target_path=target_path) else: download_session_manager_plugin_linux(target_path=target_path, pkg_format="rpm") os.chmod(target_path, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) subprocess.check_call(["session-manager-plugin"], env=dict(os.environ, PATH=PATH)) return shutil.which("session-manager-plugin", path=PATH)
Example #2
Source File: makebin.py From pydarkstar with MIT License | 7 votes |
def chmod(path): os.chmod(path, # user stat.S_IRUSR | # read stat.S_IWUSR | # write stat.S_IXUSR | # execute # group stat.S_IRGRP | # read stat.S_IWGRP | # write stat.S_IXGRP | # execute # other stat.S_IROTH | # read # stat.S_IWOTH | # write stat.S_IXOTH # execute )
Example #3
Source File: device_utils_test.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #4
Source File: 1_2_188_to_1_2_189.py From indy-node with Apache License 2.0 | 6 votes |
def set_own_perm(usr, dir_list): uid = pwd.getpwnam(usr).pw_uid gid = grp.getgrnam(usr).gr_gid perm_mask_rw = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP perm_mask_rwx = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP for cdir in dir_list: os.chown(cdir, uid, gid) os.chmod(cdir, perm_mask_rwx) for croot, sub_dirs, cfiles in os.walk(cdir): for fs_name in sub_dirs: os.chown(os.path.join(croot, fs_name), uid, gid) os.chmod(os.path.join(croot, fs_name), perm_mask_rwx) for fs_name in cfiles: os.chown(os.path.join(croot, fs_name), uid, gid) os.chmod(os.path.join(croot, fs_name), perm_mask_rw)
Example #5
Source File: examples.py From simnibs with GNU General Public License v3.0 | 6 votes |
def replace_gmsh(): fn_gmsh = path2bin('gmsh') fn_gmsh_tmp = path2bin('gmsh_tmp') # move shutil.move(fn_gmsh, fn_gmsh_tmp) # replace if sys.platform == 'win32': fn_script = fn_gmsh[:4] + '.cmd' with open(fn_script, 'w') as f: f.write('echo "GMSH"') else: with open(fn_gmsh, 'w') as f: f.write('#! /bin/bash -e\n') f.write(f'"echo" "$@"') os.chmod( fn_gmsh, os.stat(fn_gmsh).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH ) yield shutil.move(fn_gmsh_tmp, fn_gmsh)
Example #6
Source File: test_finder.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_no_read_directory(self): # Issue #16730 tempdir = tempfile.TemporaryDirectory() original_mode = os.stat(tempdir.name).st_mode def cleanup(tempdir): """Cleanup function for the temporary directory. Since we muck with the permissions, we want to set them back to their original values to make sure the directory can be properly cleaned up. """ os.chmod(tempdir.name, original_mode) # If this is not explicitly called then the __del__ method is used, # but since already mucking around might as well explicitly clean # up. tempdir.__exit__(None, None, None) self.addCleanup(cleanup, tempdir) os.chmod(tempdir.name, stat.S_IWUSR | stat.S_IXUSR) finder = self.get_finder(tempdir.name) found = self._find(finder, 'doesnotexist') self.assertEqual(found, self.NOT_FOUND)
Example #7
Source File: dependency_manager_util.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def SetUnzippedDirPermissions(archive, unzipped_dir): """Set the file permissions in an unzipped archive. Designed to be called right after extractall() was called on |archive|. Noop on Win. Otherwise sets the executable bit on files where needed. Args: archive: A zipfile.ZipFile object opened for reading. unzipped_dir: A path to a directory containing the unzipped contents of |archive|. """ if sys.platform.startswith('win'): # Windows doesn't have an executable bit, so don't mess with the ACLs. return for zip_info in archive.infolist(): archive_acls = GetModeFromZipInfo(zip_info) if archive_acls & stat.S_IXUSR: # Only preserve owner execurable permissions. unzipped_path = os.path.abspath( os.path.join(unzipped_dir, zip_info.filename)) mode = GetModeFromPath(unzipped_path) os.chmod(unzipped_path, mode | stat.S_IXUSR)
Example #8
Source File: utils.py From OneForAll with GNU General Public License v3.0 | 6 votes |
def get_massdns_path(massdns_dir): path = setting.brute_massdns_path if path: return path system = platform.system().lower() machine = platform.machine().lower() name = f'massdns_{system}_{machine}' if system == 'windows': name = name + '.exe' if machine == 'amd64': massdns_dir = massdns_dir.joinpath('windows', 'x64') else: massdns_dir = massdns_dir.joinpath('windows', 'x84') path = massdns_dir.joinpath(name) path.chmod(S_IXUSR) if not path.exists(): logger.log('FATAL', 'There is no massdns for this platform or architecture') logger.log('INFOR', 'Please try to compile massdns yourself and specify the path in the configuration') exit(0) return path
Example #9
Source File: device_utils_test.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #10
Source File: dependency_manager_util.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def SetUnzippedDirPermissions(archive, unzipped_dir): """Set the file permissions in an unzipped archive. Designed to be called right after extractall() was called on |archive|. Noop on Win. Otherwise sets the executable bit on files where needed. Args: archive: A zipfile.ZipFile object opened for reading. unzipped_dir: A path to a directory containing the unzipped contents of |archive|. """ if sys.platform.startswith('win'): # Windows doesn't have an executable bit, so don't mess with the ACLs. return for zip_info in archive.infolist(): archive_acls = GetModeFromZipInfo(zip_info) if archive_acls & stat.S_IXUSR: # Only preserve owner execurable permissions. unzipped_path = os.path.abspath( os.path.join(unzipped_dir, zip_info.filename)) mode = GetModeFromPath(unzipped_path) os.chmod(unzipped_path, mode | stat.S_IXUSR)
Example #11
Source File: cloud_storage_info_unittest.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testGetRemotePathNoArchive(self, cs_get_mock): def _GetIfHashChangedMock(cs_path, download_path, bucket, file_hash): del cs_path, bucket, file_hash if not os.path.exists(download_path): self.fs.CreateFile(download_path, contents='1010001010101010110101') cs_get_mock.side_effect = _GetIfHashChangedMock # All of the needed information is given, and the downloaded path exists # after calling cloud storage. self.assertEqual( os.path.abspath(self.download_path), self.cs_info.GetRemotePath()) self.assertTrue(os.stat(self.download_path).st_mode & stat.S_IXUSR) # All of the needed information is given, but the downloaded path doesn't # exists after calling cloud storage. self.fs.RemoveObject(self.download_path) cs_get_mock.side_effect = [True] # pylint: disable=redefined-variable-type self.assertRaises( exceptions.FileNotFoundError, self.cs_info.GetRemotePath)
Example #12
Source File: piku.py From piku with MIT License | 6 votes |
def cmd_git_receive_pack(app): """INTERNAL: Handle git pushes for an app""" app = sanitize_app_name(app) hook_path = join(GIT_ROOT, app, 'hooks', 'post-receive') env = globals() env.update(locals()) if not exists(hook_path): makedirs(dirname(hook_path)) # Initialize the repository with a hook to this script call("git init --quiet --bare " + app, cwd=GIT_ROOT, shell=True) with open(hook_path, 'w') as h: h.write("""#!/usr/bin/env bash set -e; set -o pipefail; cat | PIKU_ROOT="{PIKU_ROOT:s}" {PIKU_SCRIPT:s} git-hook {app:s}""".format(**env)) # Make the hook executable by our user chmod(hook_path, stat(hook_path).st_mode | S_IXUSR) # Handle the actual receive. We'll be called with 'git-hook' after it happens call('git-shell -c "{}" '.format(argv[1] + " '{}'".format(app)), cwd=GIT_ROOT, shell=True)
Example #13
Source File: createmanifests.py From binaryanalysis with Apache License 2.0 | 6 votes |
def cleanupdir(temporarydir): osgen = os.walk(temporarydir) try: while True: i = osgen.next() ## make sure all directories can be accessed for d in i[1]: if not os.path.islink(os.path.join(i[0], d)): os.chmod(os.path.join(i[0], d), stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR) for p in i[2]: try: if not os.path.islink(os.path.join(i[0], p)): os.chmod(os.path.join(i[0], p), stat.S_IRUSR|stat.S_IWUSR|stat.S_IXUSR) except Exception, e: #print e pass except StopIteration: pass try: shutil.rmtree(temporarydir) except: ## nothing that can be done right now, so just give up pass
Example #14
Source File: device_utils_test.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #15
Source File: dependency_manager_util.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def SetUnzippedDirPermissions(archive, unzipped_dir): """Set the file permissions in an unzipped archive. Designed to be called right after extractall() was called on |archive|. Noop on Win. Otherwise sets the executable bit on files where needed. Args: archive: A zipfile.ZipFile object opened for reading. unzipped_dir: A path to a directory containing the unzipped contents of |archive|. """ if sys.platform.startswith('win'): # Windows doesn't have an executable bit, so don't mess with the ACLs. return for zip_info in archive.infolist(): archive_acls = GetModeFromZipInfo(zip_info) if archive_acls & stat.S_IXUSR: # Only preserve owner execurable permissions. unzipped_path = os.path.abspath( os.path.join(unzipped_dir, zip_info.filename)) mode = GetModeFromPath(unzipped_path) os.chmod(unzipped_path, mode | stat.S_IXUSR)
Example #16
Source File: cloud_storage_info_unittest.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testGetRemotePathNoArchive(self, cs_get_mock): def _GetIfHashChangedMock(cs_path, download_path, bucket, file_hash): del cs_path, bucket, file_hash if not os.path.exists(download_path): self.fs.CreateFile(download_path, contents='1010001010101010110101') cs_get_mock.side_effect = _GetIfHashChangedMock # All of the needed information is given, and the downloaded path exists # after calling cloud storage. self.assertEqual( os.path.abspath(self.download_path), self.cs_info.GetRemotePath()) self.assertTrue(os.stat(self.download_path).st_mode & stat.S_IXUSR) # All of the needed information is given, but the downloaded path doesn't # exists after calling cloud storage. self.fs.RemoveObject(self.download_path) cs_get_mock.side_effect = [True] # pylint: disable=redefined-variable-type self.assertRaises( exceptions.FileNotFoundError, self.cs_info.GetRemotePath)
Example #17
Source File: lib.py From marsnake with GNU General Public License v3.0 | 6 votes |
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
Example #18
Source File: test_import.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_execute_bit_not_copied(self): # Issue 6070: under posix .pyc files got their execute bit set if # the .py file had the execute bit set, but they aren't executable. oldmask = os.umask(022) sys.path.insert(0, os.curdir) try: fname = TESTFN + os.extsep + "py" f = open(fname, 'w').close() os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) __import__(TESTFN) fn = fname + 'c' if not os.path.exists(fn): fn = fname + 'o' if not os.path.exists(fn): self.fail("__import__ did not result in creation of " "either a .pyc or .pyo file") s = os.stat(fn) self.assertEqual(stat.S_IMODE(s.st_mode), stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) finally: os.umask(oldmask) remove_files(TESTFN) unload(TESTFN) del sys.path[0]
Example #19
Source File: data_dir.py From avocado-vt with GNU General Public License v2.0 | 6 votes |
def get_tmp_dir(public=True): """ Get the most appropriate tmp dir location. :param public: If public for all users' access """ persistent_dir = settings.get_value('vt.common', 'tmp_dir', default="") if persistent_dir != "": return persistent_dir tmp_dir = None # apparmor deny /tmp/* /var/tmp/* and cause failure across tests # it is better to handle here if distro.detect().name == 'Ubuntu': tmp_dir = "/var/lib/libvirt/images" if not utils_path.usable_rw_dir(tmp_dir): logging.warning("Unable to write in '/var/lib/libvirt/images' " "on Ubuntu, apparmor might complain...") tmp_dir = None tmp_dir = data_dir.get_tmp_dir(basedir=tmp_dir) if public: tmp_dir_st = os.stat(tmp_dir) os.chmod(tmp_dir, tmp_dir_st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH | stat.S_IRGRP | stat.S_IROTH) return tmp_dir
Example #20
Source File: cloud_storage_info_unittest.py From Jandroid with BSD 3-Clause "New" or "Revised" License | 6 votes |
def testGetRemotePathNoArchive(self, cs_get_mock): def _GetIfHashChangedMock(cs_path, download_path, bucket, file_hash): del cs_path, bucket, file_hash if not os.path.exists(download_path): self.fs.CreateFile(download_path, contents='1010001010101010110101') cs_get_mock.side_effect = _GetIfHashChangedMock # All of the needed information is given, and the downloaded path exists # after calling cloud storage. self.assertEqual( os.path.abspath(self.download_path), self.cs_info.GetRemotePath()) self.assertTrue(os.stat(self.download_path).st_mode & stat.S_IXUSR) # All of the needed information is given, but the downloaded path doesn't # exists after calling cloud storage. self.fs.RemoveObject(self.download_path) cs_get_mock.side_effect = [True] # pylint: disable=redefined-variable-type self.assertRaises( exceptions.FileNotFoundError, self.cs_info.GetRemotePath)
Example #21
Source File: test_import.py From oss-ftp with MIT License | 6 votes |
def test_execute_bit_not_copied(self): # Issue 6070: under posix .pyc files got their execute bit set if # the .py file had the execute bit set, but they aren't executable. oldmask = os.umask(022) sys.path.insert(0, os.curdir) try: fname = TESTFN + os.extsep + "py" f = open(fname, 'w').close() os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) __import__(TESTFN) fn = fname + 'c' if not os.path.exists(fn): fn = fname + 'o' if not os.path.exists(fn): self.fail("__import__ did not result in creation of " "either a .pyc or .pyo file") s = os.stat(fn) self.assertEqual(stat.S_IMODE(s.st_mode), stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) finally: os.umask(oldmask) remove_files(TESTFN) unload(TESTFN) del sys.path[0]
Example #22
Source File: launcher.py From Computable with MIT License | 6 votes |
def write_batch_script(self, n): """Instantiate and write the batch script to the work_dir.""" self.n = n # first priority is batch_template if set if self.batch_template_file and not self.batch_template: # second priority is batch_template_file with open(self.batch_template_file) as f: self.batch_template = f.read() if not self.batch_template: # third (last) priority is default_template self.batch_template = self.default_template # add jobarray or queue lines to user-specified template # note that this is *only* when user did not specify a template. self._insert_queue_in_script() self._insert_job_array_in_script() script_as_string = self.formatter.format(self.batch_template, **self.context) self.log.debug('Writing batch script: %s', self.batch_file) with open(self.batch_file, 'w') as f: f.write(script_as_string) os.chmod(self.batch_file, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR)
Example #23
Source File: test_import.py From BinderFilter with MIT License | 6 votes |
def test_execute_bit_not_copied(self): # Issue 6070: under posix .pyc files got their execute bit set if # the .py file had the execute bit set, but they aren't executable. oldmask = os.umask(022) sys.path.insert(0, os.curdir) try: fname = TESTFN + os.extsep + "py" f = open(fname, 'w').close() os.chmod(fname, (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) __import__(TESTFN) fn = fname + 'c' if not os.path.exists(fn): fn = fname + 'o' if not os.path.exists(fn): self.fail("__import__ did not result in creation of " "either a .pyc or .pyo file") s = os.stat(fn) self.assertEqual(stat.S_IMODE(s.st_mode), stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) finally: os.umask(oldmask) remove_files(TESTFN) unload(TESTFN) del sys.path[0]
Example #24
Source File: 1_3_396_to_1_3_397.py From indy-node with Apache License 2.0 | 5 votes |
def set_own_perm(usr, dir): uid = pwd.getpwnam(usr).pw_uid gid = grp.getgrnam(usr).gr_gid perm_mask_rw = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP perm_mask_rwx = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP os.chown(dir, uid, gid) os.chmod(dir, perm_mask_rwx) for croot, sub_dirs, cfiles in os.walk(dir): for fs_name in sub_dirs: os.chown(os.path.join(croot, fs_name), uid, gid) os.chmod(os.path.join(croot, fs_name), perm_mask_rwx) for fs_name in cfiles: os.chown(os.path.join(croot, fs_name), uid, gid) os.chmod(os.path.join(croot, fs_name), perm_mask_rw)
Example #25
Source File: webbrowser.py From oss-ftp with MIT License | 5 votes |
def _isexecutable(cmd): if os.path.isfile(cmd): mode = os.stat(cmd)[stat.ST_MODE] if mode & stat.S_IXUSR or mode & stat.S_IXGRP or mode & stat.S_IXOTH: return True return False
Example #26
Source File: filepath.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def __init__(self, statModeInt): self.user, self.group, self.other = ( [RWX(*[statModeInt & bit > 0 for bit in bitGroup]) for bitGroup in [[S_IRUSR, S_IWUSR, S_IXUSR], [S_IRGRP, S_IWGRP, S_IXGRP], [S_IROTH, S_IWOTH, S_IXOTH]]] )
Example #27
Source File: os_utils.py From godot-mono-builds with MIT License | 5 votes |
def chmod_plus_x(file): import os import stat umask = os.umask(0) os.umask(umask) st = os.stat(file) os.chmod(file, st.st_mode | ((stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & ~umask))
Example #28
Source File: 1_3_428_to_1_3_429.py From indy-node with Apache License 2.0 | 5 votes |
def set_own_perm(usr, dir): uid = pwd.getpwnam(usr).pw_uid gid = grp.getgrnam(usr).gr_gid perm_mask_rw = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IWGRP perm_mask_rwx = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP os.chown(dir, uid, gid) os.chmod(dir, perm_mask_rwx) for croot, sub_dirs, cfiles in os.walk(dir): for fs_name in sub_dirs: os.chown(os.path.join(croot, fs_name), uid, gid) os.chmod(os.path.join(croot, fs_name), perm_mask_rwx) for fs_name in cfiles: os.chown(os.path.join(croot, fs_name), uid, gid) os.chmod(os.path.join(croot, fs_name), perm_mask_rw)
Example #29
Source File: test_iutils.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def _defaultPathTest(self, utilFunc, check): # Make another directory to mess around with. dir = os.path.abspath(self.mktemp()) os.makedirs(dir) scriptFile = self.makeSourceFile([ "import os, sys, stat", # Fix the permissions so we can report the working directory. # On OS X (and maybe elsewhere), os.getcwd() fails with EACCES # if +x is missing from the working directory. "os.chmod(%r, stat.S_IXUSR)" % (dir,), "sys.stdout.write(os.getcwd())"]) # Switch to it, but make sure we switch back self.addCleanup(os.chdir, os.getcwd()) os.chdir(dir) # Get rid of all its permissions, but make sure they get cleaned up # later, because otherwise it might be hard to delete the trial # temporary directory. self.addCleanup( os.chmod, dir, stat.S_IMODE(os.stat('.').st_mode)) os.chmod(dir, 0) # Pass in -S so that if run using the coverage .pth trick, it won't be # loaded and cause Coverage to try and get the current working # directory (see the comments above why this can be a problem) on OSX. d = utilFunc(self.exe, ['-S', '-u', scriptFile]) d.addCallback(check, dir.encode(sys.getfilesystemencoding())) return d
Example #30
Source File: common.py From pex with Apache License 2.0 | 5 votes |
def chmod_plus_x(path): """Equivalent of unix `chmod a+x path`""" path_mode = os.stat(path).st_mode path_mode &= int('777', 8) if path_mode & stat.S_IRUSR: path_mode |= stat.S_IXUSR if path_mode & stat.S_IRGRP: path_mode |= stat.S_IXGRP if path_mode & stat.S_IROTH: path_mode |= stat.S_IXOTH os.chmod(path, path_mode)