From a26eb6ed05ab75b12e7640f895a4879b556a46a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Sat, 9 May 2015 17:04:34 +0200 Subject: [PATCH] =?UTF-8?q?Version=20moins=20gourmande=20pour=20g=C3=A9n?= =?UTF-8?q?=C3=A9rer=20services.py?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Python/etc/crans/services.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Python/etc/crans/services.py b/Python/etc/crans/services.py index d28d490..b643e27 100644 --- a/Python/etc/crans/services.py +++ b/Python/etc/crans/services.py @@ -8,13 +8,15 @@ comment_start = "#" header("Services configuré sur la machine") -#print metadata.query.names_by_groups(['firewall']) +clients = metadata.query.all() +groups_dict = {} + +for client in clients: + for group in client.groups: + groups_dict.setdefault(group, []).append(client.hostname.split('.', 1)[0]) print "services = {" -groups = list(metadata.groups) -groups.sort() -for group in groups: - names = [ name.split('.', 1)[0] for name in metadata.query.names_by_groups([group])] - names.sort() - print " '%s':%s," % (group, names) +for (group_name, clients) in groups_dict.iteritems(): + clients.sort() + print " %s: %s" % (group_name, clients) print "}"