[Mac_prises] Début de passage à postgresql
This commit is contained in:
parent
c039058708
commit
baf4aa3645
1 changed files with 10 additions and 8 deletions
|
@ -10,6 +10,7 @@ from commands import getstatusoutput
|
||||||
|
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
import annuaires_pg
|
import annuaires_pg
|
||||||
|
import psycopg2
|
||||||
|
|
||||||
# nécessite apparemment que l'objet conn soit bien créé lors de l'exec
|
# nécessite apparemment que l'objet conn soit bien créé lors de l'exec
|
||||||
# de annuaires_pg, il faut être root (ou dans je ne sais quel groupe)
|
# de annuaires_pg, il faut être root (ou dans je ne sais quel groupe)
|
||||||
|
@ -17,8 +18,6 @@ import annuaires_pg
|
||||||
# (plante lamentablement quand j'essaye avec mon compte sur vo, sous
|
# (plante lamentablement quand j'essaye avec mon compte sur vo, sous
|
||||||
# ipython. Mais si je sudo ipython, ça marche...
|
# ipython. Mais si je sudo ipython, ça marche...
|
||||||
|
|
||||||
def is_really_crans(chbre):
|
|
||||||
|
|
||||||
def liste_prises_macs(switch):
|
def liste_prises_macs(switch):
|
||||||
u'''
|
u'''
|
||||||
Fonction générant un dictionnaire (macs) contenant pour chaque prise une
|
Fonction générant un dictionnaire (macs) contenant pour chaque prise une
|
||||||
|
@ -91,10 +90,13 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
split = switch.replace('.adm.crans.org', '').split('-')
|
split = switch.replace('.adm.crans.org', '').split('-')
|
||||||
bat, num_switch = split[0][-1], int(split[1][0])
|
bat, num_switch = split[0][-1], int(split[1][0])
|
||||||
|
|
||||||
|
pgsql = psycopg2.connect(database="mac_prises", user="crans")
|
||||||
|
curseur = pgsql.cursor()
|
||||||
|
|
||||||
if not os.path.isdir("bat%s/%d"%(bat, num_switch)):
|
# if not os.path.isdir("bat%s/%d"%(bat, num_switch)):
|
||||||
os.makedirs("bat%s/%d"%(bat, num_switch))
|
# os.makedirs("bat%s/%d"%(bat, num_switch))
|
||||||
|
#
|
||||||
for chbre in macs:
|
# for chbre in macs:
|
||||||
with open('bat%s/%d/%s%03d.macs'%(bat, num_switch, bat, prise), 'w') as f:
|
# with open('bat%s/%d/%s%03d.macs'%(bat, num_switch, bat, prise), 'w') as f:
|
||||||
f.writelines(sorted(macs[prise]))
|
# f.writelines(sorted(macs[prise]))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue