scripts/utils/list_droits.py

33 lines
734 B
Python
Executable file

#!/bin/bash /usr/scripts/python.sh
# -*- coding: utf-8 -*-
from lc_ldap import shortcuts
ldap = shortcuts.lc_ldap_readonly()
txts = []
adhs = ldap.search(u"droits=*")
droits={}
for adh in adhs:
for droit in adh['droits']:
droit = unicode(droit)
droits[droit] = droits.get(droit, []) + [adh]
d=droits.keys()
d.sort()
for droit in d:
adhs = droits[droit]
noms = []
txt = '%s\n' % droit
for adh in adhs :
noms.append(u'%s %s (%s)' % (adh['prenom'][0],adh['nom'][0],adh['historique'][0].split()[0].split('/',2)[-1]))
noms.sort()
txt += u' %s' % '\n '.join(noms)
txts.append(txt)
print '\n- - - - - - = = = = = = # # # # # # # # = = = = = = - - - - - -\n'.join(txts)