我们从Python开源项目中,提取了以下49个代码示例,用于说明如何使用stat.S_IXGRP。
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. with temp_umask(0o022): sys.path.insert(0, os.curdir) try: fname = TESTFN + os.extsep + "py" 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)) fn = imp.cache_from_source(fname) unlink(fn) __import__(TESTFN) 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: del sys.path[0] remove_files(TESTFN) unload(TESTFN)
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)
def make_job(subject_id_list, freesurfer_dir, base_feature, weight_method, num_bins, edge_range, atlas, fwhm, out_proc_dir, job_dir, job_name, num_procs): "Creates graynet job for running on HPC" str_list_weight_method = ' '.join(weight_method) job_file = pjoin(job_dir, '{}.graynet.job'.format(job_name)) job_log = pjoin(job_dir, '{}.graynet.log'.format(job_name)) if pexists(job_file): os.remove(job_file) with open(job_file, 'w') as jf: jf.write('#!/bin/bash\n') jf.write(specify_hpc_resources(mem, queue, num_procs, job_dir, job_log)) jf.write(make_cli_call(cli_name,realpath(subject_id_list), base_feature, realpath(freesurfer_dir), str_list_weight_method, num_bins, edge_range, atlas, fwhm, realpath(out_proc_dir), num_procs)) st = os.stat(job_file) os.chmod(job_file, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) return job_file
def make_job(subject_id_list, freesurfer_dir, base_feature, weight_method, num_bins, edge_range, summary_stat, atlas, fwhm, out_proc_dir, job_dir, job_name, num_procs): "Creates graynet job for running on HPC" str_list_weight_method = ' '.join(weight_method) job_file = pjoin(job_dir, '{}.{}.job'.format(job_name, job_type)) job_log = pjoin(job_dir, '{}.{}.log'.format(job_name, job_type)) if pexists(job_file): os.remove(job_file) with open(job_file, 'w') as jf: jf.write('#!/bin/bash\n') jf.write(specify_hpc_resources(mem, queue, num_procs, job_dir, job_log)) jf.write(make_cli_call(cli_name, realpath(subject_id_list), base_feature, realpath(freesurfer_dir), str_list_weight_method, num_bins, edge_range, summary_stat, atlas, fwhm, realpath(out_proc_dir), num_procs)) st = os.stat(job_file) os.chmod(job_file, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) return job_file
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]
def set_bad_file_permissions(context): if 'chmod' in context.call_function_name: if context.call_args_count == 2: mode = context.get_call_arg_at_position(1) if (mode is not None and isinstance(mode, int) and (mode & stat.S_IWOTH or mode & stat.S_IXGRP)): # world writable is an HIGH, group executable is a MEDIUM if mode & stat.S_IWOTH: sev_level = bandit.HIGH else: sev_level = bandit.MEDIUM filename = context.get_call_arg_at_position(0) if filename is None: filename = 'NOT PARSED' return bandit.Issue( severity=sev_level, confidence=bandit.HIGH, text="Chmod setting a permissive mask %s on file (%s)." % (oct(mode), filename) )
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(0o22) 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) assert(s.st_mode & (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)) assert(not (s.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))) finally: os.umask(oldmask) clean_tmpfiles(fname) unload(TESTFN) del sys.path[0]
def p4_edit_file(self, file_path): file_abspath, file_p4fixed = file_path p4cfg = self.target p4 = p4cfg.p4 p4.run_sync('-k', file_p4fixed) f_st = os.lstat(file_abspath) is_executable = f_st.st_mode & (stat.S_IXGRP | stat.S_IXUSR) is_symlink = os.path.islink(file_abspath) if is_symlink: output = p4.run_edit('-t', 'symlink', file_p4fixed) elif is_executable: output = p4.run_edit('-t', '+x', file_p4fixed) else: output = p4.run_edit('-t', 'auto', file_p4fixed) # If the initial 'add' change was lost # an edit on a missing file will report # an error 'not on client' if p4cfg.inWarnings('not on client'): msg = '%s not on client. Changing P4 Edit to P4 Add' % file_abspath self.logger.warning(msg) output = p4.run_add('-f', file_abspath)
def _octal_to_perm(octal): perms = list("-" * 9) if octal & stat.S_IRUSR: perms[0] = "r" if octal & stat.S_IWUSR: perms[1] = "w" if octal & stat.S_IXUSR: perms[2] = "x" if octal & stat.S_IRGRP: perms[3] = "r" if octal & stat.S_IWGRP: perms[4] = "w" if octal & stat.S_IXGRP: perms[5] = "x" if octal & stat.S_IROTH: perms[6] = "r" if octal & stat.S_IWOTH: perms[7] = "w" if octal & stat.S_IXOTH: perms[8] = "x" return "".join(perms)
def gunzip_file(gz_path, new_path): """Unzips from gz_path into new_path. Args: gz_path: path to the zipped file. new_path: path to where the file will be unzipped. """ if tf.gfile.Exists(new_path): tf.logging.info("File %s already exists, skipping unpacking" % new_path) return tf.logging.info("Unpacking %s to %s" % (gz_path, new_path)) # We may be unpacking into a newly created directory, add write mode. mode = stat.S_IRWXU or stat.S_IXGRP or stat.S_IRGRP or stat.S_IROTH os.chmod(os.path.dirname(new_path), mode) with gzip.open(gz_path, "rb") as gz_file: with tf.gfile.GFile(new_path, mode="wb") as new_file: for line in gz_file: new_file.write(line)
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
def extract_zip(data: bytes, path: Path) -> None: """Extract zipped data to path.""" # On mac zipfile module cannot extract correctly, so use unzip instead. if curret_platform() == 'mac': import subprocess import shutil zip_path = path / 'chrome.zip' if not path.exists(): path.mkdir(parents=True) with zip_path.open('wb') as f: f.write(data) if not shutil.which('unzip'): raise OSError('Failed to automatically extract chrome.zip.' f'Please unzip {zip_path} manually.') subprocess.run(['unzip', str(zip_path)], cwd=str(path)) if chromium_excutable().exists() and zip_path.exists(): zip_path.unlink() else: with ZipFile(BytesIO(data)) as zf: zf.extractall(str(path)) exec_path = chromium_excutable() if not exec_path.exists(): raise IOError('Failed to extract chromium.') exec_path.chmod(exec_path.stat().st_mode | stat.S_IXOTH | stat.S_IXGRP | stat.S_IXUSR) logger.warning(f'chromium extracted to: {path}')
def find_all_executables(folder): """ :param folder: :return: """ executable_flag = stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH return [f for f in os.listdir(folder) if os.stat(os.path.join(folder, f)).st_mode & executable_flag]
def set_executable(top): error_count=0 def set_exec(name): mode = os.stat(name).st_mode new_mode = mode if new_mode & stat.S_IRUSR: new_mode = new_mode | stat.S_IXUSR if new_mode & stat.S_IRGRP: new_mode = new_mode | stat.S_IXGRP if new_mode & stat.S_IROTH: new_mode = new_mode | stat.S_IXOTH if (mode != new_mode): print "Setting exec for '%s' (mode %o => %o)" % (name, mode, new_mode) os.chmod(name, new_mode) def unset_exec(name): mode = os.stat(name).st_mode new_mode = mode & ~(stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) if (mode != new_mode): print "Unsetting exec for '%s' (mode %o => %o)" % (name, mode, new_mode) os.chmod(name, new_mode) for root, dirs, files in os.walk(top): for name in files: complete_name = os.path.join(root, name) if os.path.islink(complete_name): continue try: f = open(complete_name, 'r') header = f.read(4) f.close() if header[0:2] == '#!' or header[1:4] == 'ELF': set_exec(complete_name) else: unset_exec(complete_name) except Exception as e: print "%s: %s" % (complete_name, e.__str__()) error_count += 1 for name in dirs: complete_name = os.path.join(root, name) set_exec(complete_name) return error_count
def is_executable(file): if not os.path.exists(file): return False st = os.stat(file) return bool(st.st_mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH))
def is_executable(mode): """ Check if mode is executable Mode can be specified in octal or as an int. """ if isinstance(mode, str) and mode.startswith('0o'): mode = int(mode, 8) ux, gx, ox = stat.S_IXUSR, stat.S_IXGRP, stat.S_IXOTH return ((mode & ux) or (mode & gx) or (mode & ox)) > 0
def is_executable_file(path): """Checks that path is an executable regular file, or a symlink towards one. This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``. """ # follow symlinks, fpath = os.path.realpath(path) if not os.path.isfile(fpath): # non-files (directories, fifo, etc.) return False mode = os.stat(fpath).st_mode if (sys.platform.startswith('sunos') and os.getuid() == 0): # When root on Solaris, os.X_OK is True for *all* files, irregardless # of their executability -- instead, any permission bit of any user, # group, or other is fine enough. # # (This may be true for other "Unix98" OS's such as HP-UX and AIX) return bool(mode & (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)) return os.access(fpath, os.X_OK)
def setup_permissions(path): file_stat = os.stat(path) os.chmod(path, file_stat.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
def assert_mode_755(mode): """Verify given mode is 755""" assert (mode & stat.S_IROTH) and (mode & stat.S_IRGRP) and (mode & stat.S_IXOTH) and (mode & stat.S_IXGRP) assert (mode & stat.S_IWUSR) and (mode & stat.S_IRUSR) and (mode & stat.S_IXUSR)
def _create_executable_script(self, script_name, content): script_path = os.path.join(self._paths.venv, '{}.bash'.format(script_name)) with open(script_path, 'w') as f: f.write(content) st = os.stat(script_path) os.chmod(script_path, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
def file_group_executable(path): """Check if a file should be group executable""" mode = path.stat().mode if stat.S_ISDIR(mode): return if bool(stat.S_IXUSR & mode) and not bool(stat.S_IXGRP & mode): return 'PROB_FILE_NOT_GRPEXEC'
def dir_group_readable(path): """Check if a directory is accessible and readable""" mode = path.stat().mode if not stat.S_ISDIR(mode): return else: if not bool(stat.S_IXGRP & mode): return 'PROB_DIR_NOT_ACCESSIBLE' elif not bool(stat.S_IWGRP & mode): return 'PROB_DIR_NOT_WRITABLE'
def statinfo(st): return { 'mode' : "%04o" % stat.S_IMODE(st.st_mode), 'isdir' : stat.S_ISDIR(st.st_mode), 'ischr' : stat.S_ISCHR(st.st_mode), 'isblk' : stat.S_ISBLK(st.st_mode), 'isreg' : stat.S_ISREG(st.st_mode), 'isfifo' : stat.S_ISFIFO(st.st_mode), 'islnk' : stat.S_ISLNK(st.st_mode), 'issock' : stat.S_ISSOCK(st.st_mode), 'uid' : st.st_uid, 'gid' : st.st_gid, 'size' : st.st_size, 'inode' : st.st_ino, 'dev' : st.st_dev, 'nlink' : st.st_nlink, 'atime' : st.st_atime, 'mtime' : st.st_mtime, 'ctime' : st.st_ctime, 'wusr' : bool(st.st_mode & stat.S_IWUSR), 'rusr' : bool(st.st_mode & stat.S_IRUSR), 'xusr' : bool(st.st_mode & stat.S_IXUSR), 'wgrp' : bool(st.st_mode & stat.S_IWGRP), 'rgrp' : bool(st.st_mode & stat.S_IRGRP), 'xgrp' : bool(st.st_mode & stat.S_IXGRP), 'woth' : bool(st.st_mode & stat.S_IWOTH), 'roth' : bool(st.st_mode & stat.S_IROTH), 'xoth' : bool(st.st_mode & stat.S_IXOTH), 'isuid' : bool(st.st_mode & stat.S_ISUID), 'isgid' : bool(st.st_mode & stat.S_ISGID), }
def is_executable(path): '''is the given path executable? Limitations: * Does not account for FSACLs. * Most times we really want to know "Can the current user execute this file" This function does not tell us that, only if an execute bit is set. ''' # These are all bitfields so first bitwise-or all the permissions we're # looking for, then bitwise-and with the file's mode to determine if any # execute bits are set. return ((stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) & os.stat(path)[stat.ST_MODE])
def create_app(name, command_to_execute, is_genymotion=False): app_file = "%s/Applications/Quick Emulators/%s.app" % (expanduser('~'), name) app_contents = "%s/Contents" % app_file app_resources = "%s/Resources" % app_contents app_mac_os = "%s/MacOS" % app_contents mkdir_p(app_file) mkdir_p(app_contents) mkdir_p(app_resources) mkdir_p(app_mac_os) # create the plist file with the app name with cd(app_contents): with open("Info.plist", 'w') as f: f.write(plist_template.format(**{"app_name": name})) # use the genymotion app icon if it exists if is_genymotion and isfile(genymotion_icon): copyfile(genymotion_icon, "%s/%s.icns" % (app_resources, name)) # write the script file and set it as executable with cd(app_mac_os): write_script_file(name, command_to_execute) st = os.stat(name) chmod_flags = st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH os.chmod(name, chmod_flags) # add tags to file that can be used by spotlight: tags = ["Android", "Emulator", ("Genymotion" if is_genymotion else "AVD")] write_xattrs(app_file, tags) # add app to spotlight index call(["mdimport", app_file])
def make_job(subject_id_list, freesurfer_dir, base_feature, roi_stat_list, atlas, fwhm, out_proc_dir, job_dir, job_name): "Creates graynet job for running on HPC" queue = 'abaqus.q' mem='2G' cli_name = 'graynet' roi_stat_list = ' '.join(roi_stat_list) job_file = pjoin(job_dir, '{}.job'.format(job_name)) job_log = pjoin(job_dir, '{}.graynet_roistats.log'.format(job_name)) if pexists(job_file): os.remove(job_file) with open(job_file, 'w') as jf: jf.write('#!/bin/bash\n') jf.write(specify_hpc_resources(mem, queue, job_dir, job_log)) cli_call_line = make_cli_call_roistats(cli_name,realpath(subject_id_list), base_feature, realpath(freesurfer_dir), roi_stat_list, atlas, fwhm, realpath(out_proc_dir)) jf.write(cli_call_line) st = os.stat(job_file) os.chmod(job_file, st.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) return job_file
def main(): parser = argparse.ArgumentParser( description='Generate a script that invokes the Dart tester') parser.add_argument('--out', help='Path to the invocation file to generate', required=True) parser.add_argument('--source-dir', help='Path to test sources', required=True) parser.add_argument('--dot-packages', help='Path to the .packages file', required=True) parser.add_argument('--test-runner', help='Path to the test runner', required=True) parser.add_argument('--flutter-shell', help='Path to the Flutter shell', required=True) args = parser.parse_args() test_file = args.out test_path = os.path.dirname(test_file) if not os.path.exists(test_path): os.makedirs(test_path) script_template = string.Template('''#!/bin/sh $test_runner \\ --packages=$dot_packages \\ --shell=$flutter_shell \\ --test-directory=$source_dir ''') with open(test_file, 'w') as file: file.write(script_template.substitute(args.__dict__)) permissions = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | stat.S_IRGRP | stat.S_IWGRP | stat.S_IXGRP | stat.S_IROTH) os.chmod(test_file, permissions)
def _write_script(output_dir, name, script): path = os.path.join(output_dir, name) with open(path, 'w') as f: f.write(script) os.chmod( path, os.stat(path).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
def stats_to_str(s): return "%s%s%s%s" % (dbpcs(s.st_mode), rwx(s.st_mode, stat.S_IRUSR, stat.S_IWUSR, stat.S_IXUSR), rwx(s.st_mode, stat.S_IRGRP, stat.S_IWGRP, stat.S_IXGRP), rwx(s.st_mode, stat.S_IROTH, stat.S_IWOTH, stat.S_IXOTH))
def add_exec(file_path): """Add execution rights for user, group and others to the given file""" print("change permissions") # change Permission with bitwies or and the constants from stat modul os.chmod(file_path, stat.S_IRUSR | stat.S_IWUSR| stat.S_IXUSR | \ stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) # global vars are very bad but I think the only solution for this
def is_executable_file(path): """Checks that path is an executable regular file (or a symlink to a file). This is roughly ``os.path isfile(path) and os.access(path, os.X_OK)``, but on some platforms :func:`os.access` gives us the wrong answer, so this checks permission bits directly. """ # follow symlinks, fpath = os.path.realpath(path) # return False for non-files (directories, fifo, etc.) if not os.path.isfile(fpath): return False # On Solaris, etc., "If the process has appropriate privileges, an # implementation may indicate success for X_OK even if none of the # execute file permission bits are set." # # For this reason, it is necessary to explicitly check st_mode # get file mode using os.stat, and check if `other', # that is anybody, may read and execute. mode = os.stat(fpath).st_mode if mode & stat.S_IROTH and mode & stat.S_IXOTH: return True # get current user's group ids, and check if `group', # when matching ours, may read and execute. user_gids = os.getgroups() + [os.getgid()] if (os.stat(fpath).st_gid in user_gids and mode & stat.S_IRGRP and mode & stat.S_IXGRP): return True # finally, if file owner matches our effective userid, # check if `user', may read and execute. user_gids = os.getgroups() + [os.getgid()] if (os.stat(fpath).st_uid == os.geteuid() and mode & stat.S_IRUSR and mode & stat.S_IXUSR): return True return False
def create_executable(exec_dir, install_dir): create_dir(exec_dir) exec_filepath = os.path.join(exec_dir, EXECUTABLE_NAME) with open(exec_filepath, 'w') as exec_file: exec_file.write(AZ_DISPATCH_TEMPLATE.format(install_dir=install_dir)) cur_stat = os.stat(exec_filepath) os.chmod(exec_filepath, cur_stat.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) print_status("The executable is available at '{}'.".format(exec_filepath)) return exec_filepath
def dcos_install_cli(install_location=None, client_version='1.8'): """ Downloads the dcos command line from Mesosphere """ system = platform.system() if not install_location: raise CLIError( "No install location specified and it could not be determined from the current platform '{}'".format( system)) base_url = 'https://downloads.dcos.io/binaries/cli/{}/x86-64/dcos-{}/{}' if system == 'Windows': file_url = base_url.format('windows', client_version, 'dcos.exe') elif system == 'Linux': # TODO Support ARM CPU here file_url = base_url.format('linux', client_version, 'dcos') elif system == 'Darwin': file_url = base_url.format('darwin', client_version, 'dcos') else: raise CLIError('Proxy server ({}) does not exist on the cluster.'.format(system)) logger.warning('Downloading client to %s', install_location) try: _urlretrieve(file_url, install_location) os.chmod(install_location, os.stat(install_location).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) except IOError as err: raise CLIError('Connection error while attempting to download client ({})'.format(err))
def k8s_install_cli(client_version='latest', install_location=None): """Install kubectl, a command-line interface for Kubernetes clusters.""" if client_version == 'latest': context = _ssl_context() version = urlopen('https://storage.googleapis.com/kubernetes-release/release/stable.txt', context=context).read() client_version = version.decode('UTF-8').strip() else: client_version = "v%s" % client_version file_url = '' system = platform.system() base_url = 'https://storage.googleapis.com/kubernetes-release/release/{}/bin/{}/amd64/{}' if system == 'Windows': file_url = base_url.format(client_version, 'windows', 'kubectl.exe') elif system == 'Linux': # TODO: Support ARM CPU here file_url = base_url.format(client_version, 'linux', 'kubectl') elif system == 'Darwin': file_url = base_url.format(client_version, 'darwin', 'kubectl') else: raise CLIError('Proxy server ({}) does not exist on the cluster.'.format(system)) logger.warning('Downloading client to %s from %s', install_location, file_url) try: _urlretrieve(file_url, install_location) os.chmod(install_location, os.stat(install_location).st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) except IOError as ex: raise CLIError('Connection error while attempting to download client ({})'.format(ex))
def test_set_config_value_file_permissions(self): with mock.patch('azure.cli.core._config.GLOBAL_CONFIG_DIR', self.config_dir), \ mock.patch('azure.cli.core._config.GLOBAL_CONFIG_PATH', self.config_path): set_global_config_value('test_section', 'test_option', 'a_value') file_mode = os.stat(self.config_path).st_mode self.assertTrue(bool(file_mode & stat.S_IRUSR)) self.assertTrue(bool(file_mode & stat.S_IWUSR)) self.assertFalse(bool(file_mode & stat.S_IXUSR)) self.assertFalse(bool(file_mode & stat.S_IRGRP)) self.assertFalse(bool(file_mode & stat.S_IWGRP)) self.assertFalse(bool(file_mode & stat.S_IXGRP)) self.assertFalse(bool(file_mode & stat.S_IROTH)) self.assertFalse(bool(file_mode & stat.S_IWOTH)) self.assertFalse(bool(file_mode & stat.S_IXOTH))
def _rename_file(src, dst): """Rename the specified file""" if os.name == 'nt': # TODO: check that fs.rm_safe works on windows, and if not, fix # fs.rm_safe. fs.rm_safe(dst) os.rename(src, dst) mode = os.stat(dst).st_mode mode |= (stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH) if _is_executable(dst): mode |= (stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) os.chmod(dst, mode)