Import oublié

This commit is contained in:
Pierre-Elliott Bécue 2014-08-25 20:43:57 +02:00
parent 3e6efb0385
commit 2fe2d18f9a

View file

@ -5,7 +5,7 @@
# ----------------- # -----------------
# #
# Copyright (C) 2013,2014: Raphaël-David Lasseri <lasseri@crans.org>, # Copyright (C) 2013,2014: Raphaël-David Lasseri <lasseri@crans.org>,
# Valentin Samir <samir@crans.org>, # Valentin Samir <samir@crans.org>,
# This file is free software; you can redistribute it and/or modify # This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or # the Free Software Foundation; either version 2 of the License, or
@ -21,6 +21,7 @@
# Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
import sys, re, datetime, string import sys, re, datetime, string
import os
import argparse import argparse
from affich_tools import coul, prompt from affich_tools import coul, prompt
import affich_tools import affich_tools
@ -32,16 +33,16 @@ import lc_ldap.filter2 as filter
if __name__ == '__main__': if __name__ == '__main__':
# Lecture de la redirection courante # Lecture de la redirection courante
def redirection_read(uid): def redirection_read(uid):
forward = open(os.path.expanduser('~%s/.forward' %uid) ,'r') forward = open(os.path.expanduser('~%s/.forward' %uid) ,'r')
print forward.read() print forward.read()
forward.close() forward.close()
return return
# Modification de la redirection # Modification de la redirection
def redirection_write(ligne,uid): def redirection_write(ligne,uid):
forward = open(os.path.expanduser('~%s/.forward' %uid),'w') forward = open(os.path.expanduser('~%s/.forward' %uid),'w')
forward.write('%s' %ligne) forward.write('%s' %ligne)
forward.close() forward.close()
return return
# On reprends whos_lc() de Valentin # On reprends whos_lc() de Valentin
if len(sys.argv) >1: if len(sys.argv) >1:
@ -49,37 +50,37 @@ if __name__ == '__main__':
result=conn.search(filter.human_to_ldap(sys.argv[1]), sizelimit=4000) result=conn.search(filter.human_to_ldap(sys.argv[1]), sizelimit=4000)
if not result: if not result:
print "Aucun résultat !" print "Aucun résultat !"
exit() exit()
else: else:
if len(result) == 1: if len(result) == 1:
if len(result[0].get(u'droits',None))==0: if len(result[0].get(u'droits',None))==0:
result[0].display() result[0].display()
uid=result[0].get(u'uid',None)[0].value uid=result[0].get(u'uid',None)[0].value
if len(result[0].get(u'droits',None))!=0: if len(result[0].get(u'droits',None))!=0:
print 'Membre actif !' print 'Membre actif !'
exit() exit()
else: else:
print lc_ldap.printing.sprint_list(result) print lc_ldap.printing.sprint_list(result)
print "%s résultats" % len(result) print "%s résultats" % len(result)
exit() exit()
else: else:
sys.stderr.write("Utiliser les filtres ldap: uid=, chbre= etc..") sys.stderr.write("Utiliser les filtres ldap: uid=, chbre= etc..")
exit() exit()
r = affich_tools.prompt(u'Confirmer sélection ? [O/N]') r = affich_tools.prompt(u'Confirmer sélection ? [O/N]')
if r == 'O' or r == 'o': if r == 'O' or r == 'o':
print "Redirection actuelle:" print "Redirection actuelle:"
redirection_read(uid) redirection_read(uid)
y = affich_tools.prompt(u'Modifier cette redirection ? [O/N]') y = affich_tools.prompt(u'Modifier cette redirection ? [O/N]')
if y == 'O' or y == 'o': if y == 'O' or y == 'o':
ligne = affich_tools.prompt(u'Nouvelle redirection:') ligne = affich_tools.prompt(u'Nouvelle redirection:')
redirection_write(ligne,uid) redirection_write(ligne,uid)
print 'Redirection effectuée !' print 'Redirection effectuée !'
elif y == 'N' or y == 'n': elif y == 'N' or y == 'n':
exit() exit()
elif r == 'N' or r == 'n': elif r == 'N' or r == 'n':
exit() exit()