26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/anamo/groups/thor.rb', line 26
def inspect output = true
un_to_uid = {};
gids_from_passwd = {}
Etc.passwd do |u|
un_to_uid[u.name] = u.uid
gids_from_passwd[u.gid] = [] unless gids_from_passwd.has_key? u.gid
gids_from_passwd[u.gid] << u.uid unless gids_from_passwd[u.gid].include? u.uid
end
ret = CSV.generate do |csv|
Etc.group do |g|
uids_in_group = g.mem.map { |un| un_to_uid[un] }
uids_in_group += gids_from_passwd[g.gid] if gids_from_passwd.has_key? g.gid
csv << [g.gid, g.name, "[#{uids_in_group.uniq.join(',')}]"]
end
end
puts ret if output
ret
end
|