当前位置: 首页>>代码示例>>Python>>正文


Python stat.S_IRUSR属性代码示例

本文整理汇总了Python中stat.S_IRUSR属性的典型用法代码示例。如果您正苦于以下问题:Python stat.S_IRUSR属性的具体用法?Python stat.S_IRUSR怎么用?Python stat.S_IRUSR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在stat的用法示例。


在下文中一共展示了stat.S_IRUSR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ensure_session_manager_plugin

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
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) 
开发者ID:kislyuk,项目名称:aegea,代码行数:19,代码来源:ssm.py

示例2: _check_cert

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def _check_cert(filename):
    """
    Does this certificate file look okay?

    Returns error message, or None if okay
    """
    try:
        st = os.stat(filename)
    except OSError:
        return filename + " doesn't exist"
    else:
        good_perm = stat.S_IFREG | stat.S_IRUSR # | stat.S_IWUSR
        if (st[stat.ST_UID], st[stat.ST_GID]) != (0,0):
            return 'not owned by root.root'
        perm = st[stat.ST_MODE]
        if good_perm != perm:
            return "expected permissions %o but found %o." % (good_perm, perm) 
开发者ID:sfu-fas,项目名称:coursys,代码行数:19,代码来源:panel.py

示例3: chmod

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
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
             ) 
开发者ID:AdamGagorik,项目名称:pydarkstar,代码行数:19,代码来源:makebin.py

示例4: cleanupdir

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
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 
开发者ID:armijnhemel,项目名称:binaryanalysis,代码行数:25,代码来源:createmanifests.py

示例5: test_rmtree

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def test_rmtree(self):
        dirpath = support.TESTFN + 'd'
        subdirpath = os.path.join(dirpath, 'subdir')
        os.mkdir(dirpath)
        os.mkdir(subdirpath)
        support.rmtree(dirpath)
        self.assertFalse(os.path.exists(dirpath))
        with support.swap_attr(support, 'verbose', 0):
            support.rmtree(dirpath)

        os.mkdir(dirpath)
        os.mkdir(subdirpath)
        os.chmod(dirpath, stat.S_IRUSR|stat.S_IXUSR)
        with support.swap_attr(support, 'verbose', 0):
            support.rmtree(dirpath)
        self.assertFalse(os.path.exists(dirpath))

        os.mkdir(dirpath)
        os.mkdir(subdirpath)
        os.chmod(dirpath, 0)
        with support.swap_attr(support, 'verbose', 0):
            support.rmtree(dirpath)
        self.assertFalse(os.path.exists(dirpath)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_test_support.py

示例6: test_execute_bit_not_copied

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
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] 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:test_import.py

示例7: test_readonly_files

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def test_readonly_files(self):
        dir = _fname
        os.mkdir(dir)
        try:
            fname = os.path.join(dir, 'db')
            f = dumbdbm.open(fname, 'n')
            self.assertEqual(list(f.keys()), [])
            for key in self._dict:
                f[key] = self._dict[key]
            f.close()
            os.chmod(fname + ".dir", stat.S_IRUSR)
            os.chmod(fname + ".dat", stat.S_IRUSR)
            os.chmod(dir, stat.S_IRUSR|stat.S_IXUSR)
            f = dumbdbm.open(fname, 'r')
            self.assertEqual(sorted(f.keys()), sorted(self._dict))
            f.close()  # don't write
        finally:
            test_support.rmtree(dir) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:20,代码来源:test_dumbdbm.py

示例8: upload_config

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def upload_config(self):
        try:
            stream = flask.request.stream
            file_path = cfg.find_config_files(project=CONF.project,
                                              prog=CONF.prog)[0]
            flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
            # mode 00600
            mode = stat.S_IRUSR | stat.S_IWUSR
            with os.fdopen(os.open(file_path, flags, mode), 'wb') as cfg_file:
                b = stream.read(BUFFER)
                while b:
                    cfg_file.write(b)
                    b = stream.read(BUFFER)

            CONF.mutate_config_files()
        except Exception as e:
            LOG.error("Unable to update amphora-agent configuration: "
                      "{}".format(str(e)))
            return webob.Response(json=dict(
                message="Unable to update amphora-agent configuration.",
                details=str(e)), status=500)

        return webob.Response(json={'message': 'OK'}, status=202) 
开发者ID:openstack,项目名称:octavia,代码行数:25,代码来源:server.py

示例9: install_netns_systemd_service

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def install_netns_systemd_service():
    os_utils = osutils.BaseOS.get_os_util()

    flags = os.O_WRONLY | os.O_CREAT | os.O_TRUNC
    # mode 00644
    mode = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH)

    # TODO(bcafarel): implement this for other init systems
    # netns handling depends on a separate unit file
    netns_path = os.path.join(consts.SYSTEMD_DIR,
                              consts.AMP_NETNS_SVC_PREFIX + '.service')

    jinja_env = jinja2.Environment(
        autoescape=True, loader=jinja2.FileSystemLoader(os.path.dirname(
            os.path.realpath(__file__)
        ) + consts.AGENT_API_TEMPLATES))

    if not os.path.exists(netns_path):
        with os.fdopen(os.open(netns_path, flags, mode), 'w') as text_file:
            text = jinja_env.get_template(
                consts.AMP_NETNS_SVC_PREFIX + '.systemd.j2').render(
                    amphora_nsname=consts.AMPHORA_NAMESPACE,
                    HasIFUPAll=os_utils.has_ifup_all())
            text_file.write(text) 
开发者ID:openstack,项目名称:octavia,代码行数:26,代码来源:util.py

示例10: upload_certificate

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def upload_certificate(self, lb_id, filename):
        self._check_ssl_filename_format(filename)

        # create directory if not already there
        if not os.path.exists(self._cert_dir(lb_id)):
            os.makedirs(self._cert_dir(lb_id))

        stream = Wrapped(flask.request.stream)
        file = self._cert_file_path(lb_id, filename)
        flags = os.O_WRONLY | os.O_CREAT
        # mode 00600
        mode = stat.S_IRUSR | stat.S_IWUSR
        with os.fdopen(os.open(file, flags, mode), 'wb') as crt_file:
            b = stream.read(BUFFER)
            while b:
                crt_file.write(b)
                b = stream.read(BUFFER)

        resp = webob.Response(json=dict(message='OK'))
        resp.headers['ETag'] = stream.get_md5()
        return resp 
开发者ID:openstack,项目名称:octavia,代码行数:23,代码来源:loadbalancer.py

示例11: write_authorized_keys

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def write_authorized_keys(name, sshkey):
    """Add the SSH key in authorize_keys with passhport call"""
    try:
        with open(config.SSH_KEY_FILE, "a", encoding="utf8") as \
                  authorized_keys_file:
                  authorized_keys_file.write('command="' + \
                                             config.PYTHON_PATH + \
                                             " " + config.PASSHPORT_PATH + \
                                             " " + name + '" ' + sshkey + "\n")
    except IOError:
        return response('ERROR: cannot write in the file ' + \
                        '"authorized_keys". However, the user is ' + \
                        'stored in the database.', 500)

    # set correct read/write permissions
    os.chmod(config.SSH_KEY_FILE, stat.S_IRUSR | stat.S_IWUSR)
    return True 
开发者ID:LibrIT,项目名称:passhport,代码行数:19,代码来源:utilities.py

示例12: save_connection_dict

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def save_connection_dict(self, fname, cdict):
        """save a connection dict to json file."""
        c = self.config
        url = cdict['registration']
        location = cdict['location']
        
        if not location:
            if PUBLIC_IPS:
                location = PUBLIC_IPS[-1]
            else:
                self.log.warn("Could not identify this machine's IP, assuming %s."
                " You may need to specify '--location=<external_ip_address>' to help"
                " IPython decide when to connect via loopback." % LOCALHOST)
                location = LOCALHOST
            cdict['location'] = location
        fname = os.path.join(self.profile_dir.security_dir, fname)
        self.log.info("writing connection info to %s", fname)
        with open(fname, 'w') as f:
            f.write(json.dumps(cdict, indent=2))
        os.chmod(fname, stat.S_IRUSR|stat.S_IWUSR) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:ipcontrollerapp.py

示例13: write_batch_script

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:launcher.py

示例14: test_rm_tree_incl_readonly_files

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def test_rm_tree_incl_readonly_files(tmpdir):
    """Test that directory trees with readonly files can be removed.

    Args:
        tmpdir (class): Fixture from pytest for creating a temporary directory
    """
    test_dir = Path(tmpdir) / "test_dir"
    read_only_dir = test_dir / "nested_read_only_dir"
    read_only_dir.mkdir(parents=True)

    test_file = read_only_dir / "test.txt"
    with io.open(test_file, "w", encoding="utf-8", errors="replace") as f:
        f.write("testing\n")

    Path.chmod(test_file, stat.S_IRUSR | stat.S_IRGRP | stat.S_IROTH)

    util.file_system_helpers.rm_tree_incl_readonly_files(test_dir) 
开发者ID:MozillaSecurity,项目名称:funfuzz,代码行数:19,代码来源:test_file_system_helpers.py

示例15: __create_pgpass_file_unix

# 需要导入模块: import stat [as 别名]
# 或者: from stat import S_IRUSR [as 别名]
def __create_pgpass_file_unix(self):
        """
        Create a .pgpass file on Unix-like operating systems.

        Permissions on this file must also be set on Unix-like systems.
        This function works on Mac OS X and Linux.
        It should work on Solaris too, but this is untested.
        """
        homedir = os.getenv('HOME')
        pgfile = homedir + os.path.sep + '.pgpass'
        if (os.path.isfile(pgfile)):
            # Set it to mode 600 (rw-------) so we can write to it
            os.chmod(pgfile, stat.S_IRUSR | stat.S_IWUSR)
        self.__write_pgpass_file(pgfile)
        # Set it to mode 400 (r------) to protect it
        os.chmod(pgfile, stat.S_IRUSR) 
开发者ID:wharton,项目名称:wrds,代码行数:18,代码来源:sql.py


注:本文中的stat.S_IRUSR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。