[annuaire] On passe sur ula base de données PgSQL

darcs-hash:20100831065041-ffbb2-c44e28237d99ba472e0465ad88f1cd7149e3081d.gz
This commit is contained in:
Nicolas Dandrimont 2010-08-31 08:50:41 +02:00
parent 337905013d
commit a1427076b5
15 changed files with 32 additions and 35 deletions

View file

@ -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()

View file

@ -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:]

View file

@ -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)

View file

@ -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:

View file

@ -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] == '-' :

View file

@ -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'

View file

@ -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

View file

@ -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

View file

@ -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 :

View file

@ -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

View file

@ -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_"

View file

@ -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())

View file

@ -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

View file

@ -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

View file

@ -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]