From a5ddd73ce555e8284b7715140b92a0d4a5b705f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Elliott=20B=C3=A9cue?= Date: Tue, 18 Aug 2015 03:50:31 +0200 Subject: [PATCH] Nettoie list_exempt.py --- utils/list_exempt.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/utils/list_exempt.py b/utils/list_exempt.py index 777e59c9..34e7d9d4 100755 --- a/utils/list_exempt.py +++ b/utils/list_exempt.py @@ -1,22 +1,29 @@ #!/bin/bash /usr/scripts/python.sh # -*- coding: utf-8 -*- +# +# list_exempt.py --- Fournit la liste des machines avec une exemption. +"""Fournit une liste des machines d'adhérents disposant d'une exemption""" from lc_ldap import shortcuts +from config.encoding import out_encoding -ldap = shortcuts.lc_ldap_readonly() +def make_output(ldap): + """Génère le texte à afficher""" + machines_avec_exemption = ldap.search(u"exempt=*") + output = [] -machines = ldap.search(u"exempt=*") + for m in machines_avec_exemption: + # texte pour la machine + txt = u'' + txt += u'Propriétaire : %s\n' % m.proprio() + txt += u'Machine : %s\n' % m['host'][0] + txt += u'destination : %s\n' % ', '.join([unicode(i) for i in m['exempt']]) -txts = [] + output.append(txt.strip()) + return output -for m in machines : +if __name__ == '__main__': + LDAP = shortcuts.lc_ldap_readonly() + OUTPUT = make_output(LDAP) - # texte pour la machine - txt = u'' - txt += u'Propriétaire : %s\n' % str(m.proprio()).decode('utf8') - txt += u'Machine : %s\n' % m['host'][0] - txt += u'destination : %s\n' % ', '.join([unicode(i) for i in m['exempt']]) - - txts.append(txt.strip()) - -print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts) + print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(OUTPUT).encode(out_encoding)