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
评论列表
文章目录