Split de lc_ldap.py en lc_ldap.py et objets.py + création du wrapper shortcuts.py

Ça permet de faire les choses sales du genre os.getenv("SUDO_USER") ou import_secrets
dans le wrapper et pas dans le binding même.
This commit is contained in:
Vincent Le Gallic 2013-05-16 06:59:14 +02:00
parent a620f5b5e9
commit db7d41d967
8 changed files with 968 additions and 867 deletions

27
test.py
View file

@ -1,15 +1,23 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# import lib standard
import psycopg2
import traceback
import random
import string
import os
import sys
## import dans /usr/scripts/
sys.path.append("/usr/scripts/")
import lc_ldap
from gestion.affich_tools import anim, OK, cprint, ERREUR
## import locaux
import lc_ldap
import shortcuts
import variables
show_traceback = False
if "--traceback" in sys.argv:
show_traceback = True
@ -124,8 +132,7 @@ def tests_machines(parent_dn, realm_list, ipsec=False):
print "Test de la librairie lc_ldap"
print "Connection"
current_user = os.getenv("SUDO_USER") or os.getenv("USER")
conn= lc_ldap.lc_ldap_test(user=current_user)
conn = shortcuts.lc_ldap_test()
print u"Tests effectués avec les droits %s " % ', '.join(conn.droits)
@ -174,7 +181,7 @@ anim("Creation d'un adherent")
try:
adherent = conn.newAdherent(adherent_ldif)
adherent.create()
except:
except Exception:
print ERREUR
print traceback.format_exc()
adherent = None
@ -191,8 +198,8 @@ else:
# Création et suppression de machines Crans #
#############################################
tests_machines(lc_ldap.base_dn, ["adm", "serveurs", "serveurs-v6", "adm-v6"])
tests_machines(lc_ldap.base_dn, ["bornes"])
tests_machines(variables.base_dn, ["adm", "serveurs", "serveurs-v6", "adm-v6"])
tests_machines(variables.base_dn, ["bornes"])
######################
@ -204,7 +211,7 @@ try:
club = conn.newClub(club_ldif)
club['responsable'] = str(adherent['aid'][0])
club.create()
except:
except Exception:
print ERREUR
print traceback.format_exc()
else:
@ -216,7 +223,7 @@ else:
try:
club = conn.search('cid=%s' % club['cid'][0], mode='rw')[0]
club.delete()
except:
except Exception:
print ERREUR
print traceback.format_exc()
else: print OK
@ -234,7 +241,7 @@ if adherent:
try:
adherent = conn.search('aid=%s' % adherent['aid'][0], mode='rw')[0]
adherent.delete()
except:
except Exception:
print ERREUR
print traceback.format_exc()
else: print OK
@ -256,7 +263,7 @@ else:
try:
facture = conn.search('fid=%s' % facture['fid'][0], mode='rw')[0]
facture.delete()
except:
except Exception:
print ERREUR
print traceback.format_exc()
else: print OK