diff --git a/adm/analyse-batg.py b/adm/analyse-batg.py index 1327ae5c..c96188af 100644 --- a/adm/analyse-batg.py +++ b/adm/analyse-batg.py @@ -12,7 +12,7 @@ Il affiche 3 colonnes : import sys sys.path.append('/usr/scripts/gestion') -from annuaires import reverse +from annuaires_pg import reverse from ldap_crans import crans_ldap from affich_tools import tableau db = crans_ldap() diff --git a/adm/chambre b/adm/chambre index 4441e86a..1429f3ca 100644 --- a/adm/chambre +++ b/adm/chambre @@ -10,7 +10,7 @@ prise [chambre] [on|off] import sys, os sys.path.append('/usr/scripts/gestion') -from annuaires import chbre_prises +from annuaires_pg import chbre_prises from hptools import hpswitch if len(sys.argv)!=3 or not sys.argv[2] in ['on','off']: @@ -22,7 +22,7 @@ bat = sys.argv[1][0].lower() chbre = sys.argv[1][1:].lower() # determination de la prise sur le switch -prise = chbre_prises[bat][chbre] +prise = chbre_prises(bat, chbre) switch = prise[0] prise = prise[1:] diff --git a/gestion/ajoute_chambre.py b/gestion/ajoute_chambre.py index 5fb889e0..cb2eacdf 100644 --- a/gestion/ajoute_chambre.py +++ b/gestion/ajoute_chambre.py @@ -32,6 +32,8 @@ import sys, os sys.path.append('/usr/scripts/gestion') +raise EnvironmentError("Ce script est *vieux*") + from annuaires import chbre_prises, reverse, bat_switchs from affich_tools import cprint @@ -60,7 +62,7 @@ prise doit être de la forme bnnn[g/d], ou nnn[g/d], dans ce dernier cas le bât prise = prise[1:] - if chbre_prises[bat].get(chbre): + if chbre_prises(bat).get(chbre): return 'chambre_deja_cablee' # dico = reverse(bat) diff --git a/gestion/gen_confs/switchs.py b/gestion/gen_confs/switchs.py index 1fee4f0c..ec2ee48e 100644 --- a/gestion/gen_confs/switchs.py +++ b/gestion/gen_confs/switchs.py @@ -19,14 +19,12 @@ import sys, os, commands, smtplib, tempfile, getopt sys.path.append('/usr/scripts/gestion') from hptools import hpswitch, sw_chbre from ldap_crans import crans_ldap, BorneWifi -from annuaires import chbre_prises, uplink_prises, reverse, bat_manuels, all_switchs +from annuaires_pg import uplink_prises, reverse, bat_manuels, all_switchs, bat_switchs from random import shuffle from gen_confs import * from time import localtime import config -from annuaires import bat_switchs - try: any except NameError: diff --git a/gestion/hptools.py b/gestion/hptools.py index dd2c1697..b24ae0b2 100644 --- a/gestion/hptools.py +++ b/gestion/hptools.py @@ -13,7 +13,7 @@ from time import sleep from popen2 import popen3 from sys import stderr, path from commands import getstatusoutput -from annuaires import chbre_prises, all_switchs +from annuaires_pg import chbre_prises, all_switchs from os.path import exists from os import system import sys @@ -415,7 +415,7 @@ class sw_chbre(hpswitch) : self.chbre = chbre try : bat = chbre[0].lower() - prise = chbre_prises[bat][chbre[1:]] + prise = chbre_prises(bat, chbre[1:]) self.prise_brute = prise self.switch = 'bat%s-%i.adm.crans.org' % (bat , int(prise[0]) ) if prise[-1] == '-' : diff --git a/gestion/ldap_crans.py b/gestion/ldap_crans.py index 1c7910e6..9fd6d1d4 100644 --- a/gestion/ldap_crans.py +++ b/gestion/ldap_crans.py @@ -13,7 +13,8 @@ from socket import gethostname import smtplib, re, os, random, string, time, sys, pwd import ldap, ldap.modlist, ldap_passwd -import config, annuaires, iptools, cPickle, config_mail +import annuaires_pg as annuaires +import config, iptools, cPickle, config_mail from chgpass import chgpass from affich_tools import coul, prompt, cprint from email_tools import send_email @@ -875,7 +876,7 @@ class CransLdap: """ Renvoie un proprietaire ou un adherent correspondant au login/ mot de passe (mot de passe facultatif) - """ + """ recherche = self.search(("uid=%s" % uid), mode) proprio = None @@ -1949,9 +1950,9 @@ class Adherent(BaseProprietaire): new = new.capitalize() bat = new[0].lower() - if bat in annuaires.chbre_prises.keys(): + if bat in annuaires.bat_switchs: # On a la liste des chambres - chbres = annuaires.chbre_prises[bat].keys() + chbres = annuaires.chbre_prises(bat).keys() if new[1:] not in chbres or len(new)<4 or not new[1:4].isdigit(): chbres.sort() aide = u"Chambre inconnue dans le batiment, les chambres valides sont :" @@ -1965,7 +1966,6 @@ class Adherent(BaseProprietaire): aide += c.ljust(5) a = a+1 aide += u'\n' - aide += u" " + annuaires.aide.get(bat, '') raise ValueError(aide) else: @@ -2781,9 +2781,9 @@ Contactez nounou si la MAC est bien celle d'une carte.""", 3) return decode(self._data.get('prise', ['N/A'])[0]) else: chbre = self.proprietaire().chbre() - if chbre and chbre[0].lower() in annuaires.chbre_prises.keys(): + if chbre and chbre[0].lower() in annuaires.bat_switchs: try: - return annuaires.chbre_prises[chbre[0].lower()][chbre[1:]] + return annuaires.chbre_prises(chbre[0], chbre[1:]) except: return 'N/A' diff --git a/gestion/majswitch.py b/gestion/majswitch.py index 8590c038..98d33550 100644 --- a/gestion/majswitch.py +++ b/gestion/majswitch.py @@ -8,7 +8,7 @@ J.Benoist Leger """ from time import sleep -from annuaires import all_switchs +from annuaires_pg import all_switchs import pexpect import getopt import sys diff --git a/gestion/tools/locate_mac.py b/gestion/tools/locate_mac.py index ac3e9d71..b6582ba9 100755 --- a/gestion/tools/locate_mac.py +++ b/gestion/tools/locate_mac.py @@ -9,7 +9,7 @@ import threading sys.path.append('/usr/scripts/gestion') from ldap_crans import crans_ldap import whos -from annuaires import reverse, all_switchs +from annuaires_pg import all_switchs from hptools import hpswitch # mise en forme d'une adresse mac diff --git a/gestion/whos.py b/gestion/whos.py index bcab7d82..2a8f74cb 100644 --- a/gestion/whos.py +++ b/gestion/whos.py @@ -1152,13 +1152,10 @@ def __recherche() : prise = arg.split('=')[1] # Récupération de la chambre try: - from annuaires import reverse - chbre = reverse(prise[0].lower())[prise[1:]] + from annuaires_pg import reverse + chbre = reverse(prise[0].lower(), prise[1:]) except KeyError: - try: - chbre = reverse(prise[0].lower())[prise[1:]+'-'] - except KeyError: - chbre=None + chbre=None if chbre: if len(chbre) != 1 : diff --git a/munin/audimat b/munin/audimat index 1faf1e3f..0e81eaea 100644 --- a/munin/audimat +++ b/munin/audimat @@ -10,7 +10,7 @@ Frédéric Pauget, Nicolas Salles, Etienne Chové import sys, os sys.path.append('/usr/scripts/gestion') from hptools import hpswitch -from annuaires import all_switchs, uplink_prises +from annuaires_pg import all_switchs, uplink_prises #################################################################### ## Définition des chaines à audimater diff --git a/munin/scripts/hosts_plugins.py b/munin/scripts/hosts_plugins.py index eca773e7..02716711 100755 --- a/munin/scripts/hosts_plugins.py +++ b/munin/scripts/hosts_plugins.py @@ -98,7 +98,7 @@ for net in config.NETs: hosts_plugins["munin"]["stats-ip_%s" % net] = "stats-ip_" # Stats de peuplement des bâtiments -for bat in annuaires.chbre_prises: +for bat in annuaires.bat_switchs: if bat not in ('v',): hosts_plugins["munin"]["stats-batiment_%s" % bat] = "stats-batiment_" diff --git a/munin/stats-batiment_ b/munin/stats-batiment_ index fd4361b3..da37f488 100644 --- a/munin/stats-batiment_ +++ b/munin/stats-batiment_ @@ -7,7 +7,7 @@ import sys,os,string sys.path.append('/usr/scripts/gestion') -from annuaires import reverse, chbre_prises, bat_switchs, all_switchs, uplink_prises +from annuaires_pg import reverse, chbre_prises, bat_switchs, all_switchs, uplink_prises from hptools import hpswitch from ldap_crans import crans_ldap @@ -127,6 +127,6 @@ else : if BAT in BAT_CHBRES.keys() : print "chbres.value %d" % BAT_CHBRES[BAT] - print "connues.value %d" % len(chbre_prises[BAT].keys()) + print "connues.value %d" % len(chbre_prises(BAT).keys()) else : - print "chbres.value %d" % len(chbre_prises[BAT].keys()) + print "chbres.value %d" % len(chbre_prises(BAT).keys()) diff --git a/surveillance/demenagement.py b/surveillance/demenagement.py index 96ba2431..87d83348 100644 --- a/surveillance/demenagement.py +++ b/surveillance/demenagement.py @@ -10,7 +10,7 @@ Auteur : import sys, os sys.path.append('/usr/scripts/gestion') from hptools import hpswitch -from annuaires import all_switchs, bat_switchs, reverse, uplink_prises +from annuaires_pg import all_switchs, bat_switchs, reverse, uplink_prises from ldap_crans import crans_ldap from affich_tools import anim, OK from email_tools import send_email diff --git a/surveillance/parse_auth_log.py b/surveillance/parse_auth_log.py index 4cccaf31..73c6c410 100644 --- a/surveillance/parse_auth_log.py +++ b/surveillance/parse_auth_log.py @@ -30,7 +30,7 @@ import sys sys.path.append('/usr/scripts/gestion') from ldap_crans import crans_ldap -from annuaires import chbre_prises, reverse +from annuaires_pg import chbre_prises, reverse from affich_tools import cprint import sys, datetime @@ -65,7 +65,7 @@ def trouve_prise(chbre): return chbre else: bat = chbre[0].lower() - prise = bat + chbre_prises[bat][chbre[1:]] + prise = bat + chbre_prises(bat, chbre[1:]) if prise[-1] == '-': prise = prise[:-1] return prise diff --git a/surveillance/statsVlans.py b/surveillance/statsVlans.py index 139479eb..9760bbb5 100644 --- a/surveillance/statsVlans.py +++ b/surveillance/statsVlans.py @@ -18,7 +18,7 @@ from sys import path path.append('/usr/scripts/gestion') -from annuaires import chbre_prises +from annuaires_pg import chbre_prises, bat_switchs from affich_tools import * from ldap_crans import crans_ldap from ldap_crans import MachineCrans, MachineWifi, BorneWifi @@ -61,7 +61,7 @@ def scan_bats(bats, annuaire=chbre_prises, verbose=False): # On Commence par itérer sur chaque batiment : for bat in bats: prises = dict() - for chbre, prise in annuaire[bat].iteritems(): + for chbre, prise in annuaire(bat).iteritems(): prises[prise] = chbre current_switch = -1 @@ -232,7 +232,7 @@ if __name__ == "__main__": if bats == 'all': # On récupère tous les bâtiments contenus dans l'annuaire : - lbats = chbre_prises.keys() + lbats = bat_switchs else: # On génère une liste avec les bâtiments pour être propre lbats = [bat for bat in bats]