provider.py 文件源码

python
阅读 38 收藏 0 点赞 0 评论 0

项目:landscape-client 作者: CanonicalLtd 项目源码 文件源码
def get_users(self):
        """Returns a list of all local users on the computer.

        Each user is represented as a dict with the keys: C{username},
        C{name}, C{uid}, C{enabled}, C{location}, C{work-phone} and
        C{home-phone}.
        """
        users = []
        found_usernames = set()
        for user in self.get_user_data():
            if not isinstance(user, struct_passwd):
                user = struct_passwd(user)
            if user.pw_name in found_usernames:
                continue
            gecos_data = [x or None for x in user.pw_gecos.split(",")[:4]]
            while len(gecos_data) < 4:
                gecos_data.append(None)
            name, location, work_phone, home_phone = tuple(gecos_data)
            enabled = user.pw_name not in self.locked_users
            users.append({"username": user.pw_name, "name": name,
                          "uid": user.pw_uid, "enabled": enabled,
                          "location": location, "work-phone": work_phone,
                          "home-phone": home_phone,
                          "primary-gid": user.pw_gid})
            found_usernames.add(user.pw_name)
        return users
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号