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


Python pwd.getpwall方法代码示例

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


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

示例1: test_restore_nonexistent_user_group

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def test_restore_nonexistent_user_group():
    tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
    try:
        path = tmpdir + '/foo'
        os.mkdir(path)
        m = metadata.from_path(path, archive_path=path, save_symlinks=True)
        WVPASSEQ(m.path, path)
        junk,m.owner = max([(len(x.pw_name), x.pw_name + 'x')
        		    for x in pwd.getpwall()])
        junk,m.group = max([(len(x.gr_name), x.gr_name + 'x')
                            for x in grp.getgrall()])
        WVPASSEQ(m.apply_to_path(path, restore_numeric_ids=True), None)
        WVPASSEQ(os.stat(path).st_uid, m.uid)
        WVPASSEQ(os.stat(path).st_gid, m.gid)
        WVPASSEQ(m.apply_to_path(path, restore_numeric_ids=False), None)
        WVPASSEQ(os.stat(path).st_uid, m.uid)
        WVPASSEQ(os.stat(path).st_gid, m.gid)
    finally:
        subprocess.call(['rm', '-rf', tmpdir]) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:tmetadata.py

示例2: enable_local_users

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def enable_local_users(self):
        passwd_cmd = 'passwd -u {}'
        change_home = 'usermod -m -d {0} {1}'
        change_username = 'usermod -l {0} {1}'
        content = self.util.read_file('/etc/passwd')
        for p in pwd.getpwall():
            if not sysx.shell_is_interactive(p.pw_shell):
                continue
            if p.pw_uid == 0:
                continue
            if p.pw_name in content:
                new_home_dir = p.pw_dir.rstrip('-local/') + '/'
                new_username = p.pw_name.rstrip('-local')
                self.util.execute(passwd_cmd.format(p.pw_name))
                self.util.execute(change_username.format(new_username, p.pw_name))
                self.util.execute(change_home.format(new_home_dir, new_username))
                self.logger.debug("User: '{0}' will be enabled and changed username and home directory of username".format(p.pw_name)) 
开发者ID:Pardus-LiderAhenk,项目名称:ahenk,代码行数:19,代码来源:registration.py

示例3: get_system

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def get_system(uid=None):
    """
    Get all system users.

    :param str id: ID of single user to fetch
    :param str name: username of single user to fetch
    :returns: SystemUser(s)
    :rtype: SystemUser or list thereof
    """
    r = []
    grps = groups.get_system()
    for x in pwd.getpwall():
        if x.pw_name == "root":
            continue
        su = SystemUser(name=x.pw_name, uid=x.pw_uid)
        for y in grps:
            if su.name in y.users:
                su.groups.append(y.name)
        if uid == su.name:
            return su
        r.append(su)
    return sorted(r, key=lambda x: x.uid) if not uid else None 
开发者ID:arkOScloud,项目名称:core,代码行数:24,代码来源:users.py

示例4: wmfactory_directory

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def wmfactory_directory(self, request):
        m = []
        for user in pwd.getpwall():
            pw_name, pw_passwd, pw_uid, pw_gid, pw_gecos, pw_dir, pw_shell \
                     = user
            realname = string.split(pw_gecos,',')[0]
            if not realname:
                realname = pw_name
            if os.path.exists(os.path.join(pw_dir, self.userDirName)):
                m.append({
                        'href':'%s/'%pw_name,
                        'text':'%s (file)'%realname
                })
            twistdsock = os.path.join(pw_dir, self.userSocketName)
            if os.path.exists(twistdsock):
                linknm = '%s.twistd' % pw_name
                m.append({
                        'href':'%s/'%linknm,
                        'text':'%s (twistd)'%realname})
        return m 
开发者ID:kenorb-contrib,项目名称:BitTorrent,代码行数:22,代码来源:distrib.py

示例5: nobody_uid

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def nobody_uid():
    """Internal routine to get nobody's uid"""
    global nobody
    if nobody:
        return nobody
    try:
        import pwd
    except ImportError:
        return -1
    try:
        nobody = pwd.getpwnam('nobody')[2]
    except KeyError:
        nobody = 1 + max(x[2] for x in pwd.getpwall())
    return nobody 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:16,代码来源:server.py

示例6: nobody_uid

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def nobody_uid():
    """Internal routine to get nobody's uid"""
    global nobody
    if nobody:
        return nobody
    try:
        import pwd
    except ImportError:
        return -1
    try:
        nobody = pwd.getpwnam('nobody')[2]
    except KeyError:
        nobody = 1 + max(map(lambda x: x[2], pwd.getpwall()))
    return nobody 
开发者ID:glmcdona,项目名称:meddle,代码行数:16,代码来源:CGIHTTPServer.py

示例7: add_all_users_to_dial_out

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def add_all_users_to_dial_out():
    allUsers = [p[0] for p in pwd.getpwall()]
    with click.progressbar(allUsers) as bar:
        for user in bar:
            subprocess.call(["sudo", "adduser", user, "dialout"], stdout=subprocess.PIPE) 
开发者ID:bq,项目名称:web2board,代码行数:7,代码来源:web2board_installer.py

示例8: setUp

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def setUp(self):
        if POSIX:
            import pwd
            import grp
            users = pwd.getpwall()
            groups = grp.getgrall()
            self.all_uids = set([x.pw_uid for x in users])
            self.all_usernames = set([x.pw_name for x in users])
            self.all_gids = set([x.gr_gid for x in groups]) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:11,代码来源:test_contracts.py

示例9: _get_system_users

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def _get_system_users():
            """Return all users defined on the UNIX system."""
            # there should be no need to convert usernames to unicode
            # as UNIX does not allow chars outside of ASCII set
            return [entry.pw_name for entry in pwd.getpwall()] 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:7,代码来源:authorizers.py

示例10: getpwall

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def getpwall():
    rv = []
    for pw in pwd.getpwall():
        rv.append(PWEntry(pw))
    return rv 
开发者ID:kdart,项目名称:pycopia,代码行数:7,代码来源:passwd.py

示例11: home_shell

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def home_shell():
	user_shell = "unknown"
	user_home = "unknown"
	users = pwd.getpwall()

	for user in users:
		if user[0] == getpass.getuser():
			user_home = user[5]
			user_shell = user[6]
			break

	return user_home, user_shell 
开发者ID:turingsec,项目名称:marsnake,代码行数:14,代码来源:overview.py

示例12: record_account

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def record_account(self):
		fingerprint = Kdatabase().get_obj("fingerprint")

		if common.is_linux():
			import pwd
			pwall_users = pwd.getpwall() 
开发者ID:turingsec,项目名称:marsnake,代码行数:8,代码来源:__init__.py

示例13: test_expanduser

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def test_expanduser(self):
        P = self.cls
        support.import_module('pwd')
        import pwd
        pwdent = pwd.getpwuid(os.getuid())
        username = pwdent.pw_name
        userhome = pwdent.pw_dir.rstrip('/')
        # find arbitrary different user (if exists)
        for pwdent in pwd.getpwall():
            othername = pwdent.pw_name
            otherhome = pwdent.pw_dir.rstrip('/')
            if othername != username and otherhome:
                break

        p1 = P('~/Documents')
        p2 = P('~' + username + '/Documents')
        p3 = P('~' + othername + '/Documents')
        p4 = P('../~' + username + '/Documents')
        p5 = P('/~' + username + '/Documents')
        p6 = P('')
        p7 = P('~fakeuser/Documents')

        with support.EnvironmentVarGuard() as env:
            env.pop('HOME', None)

            self.assertEqual(p1.expanduser(), P(userhome) / 'Documents')
            self.assertEqual(p2.expanduser(), P(userhome) / 'Documents')
            self.assertEqual(p3.expanduser(), P(otherhome) / 'Documents')
            self.assertEqual(p4.expanduser(), p4)
            self.assertEqual(p5.expanduser(), p5)
            self.assertEqual(p6.expanduser(), p6)
            self.assertRaises(RuntimeError, p7.expanduser)

            env['HOME'] = '/tmp'
            self.assertEqual(p1.expanduser(), P('/tmp/Documents'))
            self.assertEqual(p2.expanduser(), P(userhome) / 'Documents')
            self.assertEqual(p3.expanduser(), P(otherhome) / 'Documents')
            self.assertEqual(p4.expanduser(), p4)
            self.assertEqual(p5.expanduser(), p5)
            self.assertEqual(p6.expanduser(), p6)
            self.assertRaises(RuntimeError, p7.expanduser) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:43,代码来源:test_pathlib.py

示例14: test_uid_option

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def test_uid_option(self):
        """
        Make sure ``sudo`` can be used to switch users based on a user ID.

        The purpose of this test is to switch to any user that is not root or
        the current user and verify that switching worked correctly. It's
        written this way because I wanted to make the least possible
        assumptions about the systems that will run this test suite.
        """
        uids_to_ignore = (0, os.getuid())
        entry = next(e for e in pwd.getpwall() if e.pw_uid not in uids_to_ignore)
        output = execute('id', '-u', capture=True, uid=entry.pw_uid)
        assert output == str(entry.pw_uid) 
开发者ID:xolox,项目名称:python-executor,代码行数:15,代码来源:tests.py

示例15: test_user_option

# 需要导入模块: import pwd [as 别名]
# 或者: from pwd import getpwall [as 别名]
def test_user_option(self):
        """
        Make sure ``sudo`` can be used to switch users based on a username.

        The purpose of this test is to switch to any user that is not root or
        the current user and verify that switching worked correctly. It's
        written this way because I wanted to make the least possible
        assumptions about the systems that will run this test suite.
        """
        uids_to_ignore = (0, os.getuid())
        entry = next(e for e in pwd.getpwall() if e.pw_uid not in uids_to_ignore)
        output = execute('id', '-u', capture=True, user=entry.pw_name)
        assert output == str(entry.pw_uid) 
开发者ID:xolox,项目名称:python-executor,代码行数:15,代码来源:tests.py


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