From f9104060961b64526185617aac55004b4d8863ee Mon Sep 17 00:00:00 2001 From: glondu Date: Fri, 28 Sep 2007 15:38:38 +0200 Subject: [PATCH] Amlioration de la lisibilit. darcs-hash:20070928133838-68412-9f7147534d8da0bbe861c4946b4a668291991b65.gz --- gestion/tools/locate-mac.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/gestion/tools/locate-mac.py b/gestion/tools/locate-mac.py index 57334a7e..7cb85518 100755 --- a/gestion/tools/locate-mac.py +++ b/gestion/tools/locate-mac.py @@ -10,7 +10,8 @@ sys.path.append('/usr/scripts/gestion') from ldap_crans import crans_ldap import whos from annuaires import reverse, all_switchs -from hptools import hpswitch +from hptools import hpswitch, ConversationError +from affich_tools import coul, cprint # mise en forme d'une adresse mac def format_mac(unformated_mac): @@ -32,7 +33,10 @@ class interroge_switch (threading.Thread) : prise = None iteration = 3 while (prise==None) & (iteration > 0): - prise = sw.where_is_mac(self.mac) + try: + prise = sw.where_is_mac(self.mac) + except ConversationError: + self.reponse = coul("Impossible de communiquer avec %s !" % self.switch, "jaune") iteration = iteration-1 if (prise != None): nom=sw.nom(None,prise) @@ -66,8 +70,6 @@ def trace_machine(mac, affiche_uplinks=False): for t in tableau: t.join() - resultat = u'Traçage de %s...\n' % mac - tracage = u'' for t in tableau: if t.reponse: @@ -75,12 +77,13 @@ def trace_machine(mac, affiche_uplinks=False): if tracage == u'': tracage = u"Adresse MAC inconnue des switchs\n" - return (resultat + tracage) + return tracage # on interroge les switchs et on fait un whos sur la mac if __name__ == '__main__': mac = format_mac(sys.argv[1]) affiche_uplinks = len(sys.argv) > 2 and bool(sys.argv[2]) + cprint(u'Traçage de %s...\n' % mac, "rouge") print trace_machine(mac, affiche_uplinks) print system('/usr/scripts/gestion/whos.py -a mac=%s' % mac)