def get_group_data(self):
"""
Parse group(5) formatted files and return tuples of group data in the
form (groupname, group password, group id and a list of member
usernames).
"""
group_data = []
group_file = open(self._group_file, "r")
reader = csv.DictReader(group_file, fieldnames=self.group_fields,
delimiter=":", quoting=csv.QUOTE_NONE)
current_line = 0
for row in reader:
current_line += 1
# Skip if we find the NIS marker
if (row["name"].startswith("+") or row["name"].startswith("-")):
continue
try:
group_data.append((row["name"], row["passwd"], int(row["gid"]),
row["members"].split(",")))
except (AttributeError, ValueError):
logging.warn("group file %s is incorrectly formatted: "
"line %d." % (self._group_file, current_line))
group_file.close()
return group_data
评论列表
文章目录