nested levels

This commit is contained in:
root 2012-10-25 21:10:53 +02:00
parent 428ea27e34
commit e57bb88717

View file

@ -202,6 +202,7 @@ class YunoHostLDAP(Singleton):
pwd = False pwd = False
conn = ldap.initialize('ldap://localhost:389') conn = ldap.initialize('ldap://localhost:389')
base = 'dc=yunohost,dc=org' base = 'dc=yunohost,dc=org'
level = 0
def __enter__(self): def __enter__(self):
return self return self
@ -220,13 +221,19 @@ class YunoHostLDAP(Singleton):
self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow')) self.pwd = getpass.getpass(colorize(_('Admin Password: '), 'yellow'))
except KeyboardInterrupt, EOFError: except KeyboardInterrupt, EOFError:
raise YunoHostError(125, _("Interrupted")) raise YunoHostError(125, _("Interrupted"))
self.level = self.level+1
print self.level
try: try:
self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd) self.conn.simple_bind_s('cn=admin,' + self.base, self.pwd)
except ldap.INVALID_CREDENTIALS: except ldap.INVALID_CREDENTIALS:
raise YunoHostError(13, _('Invalid credentials')) raise YunoHostError(13, _('Invalid credentials'))
def __exit__(self, type, value, traceback): def __exit__(self, type, value, traceback):
pass self.level = self.level-1
if self.level == 0:
try: self.disconnect()
except: pass
def disconnect(self): def disconnect(self):
""" """
@ -237,6 +244,7 @@ class YunoHostLDAP(Singleton):
""" """
try: try:
print 'WIN !'
self.conn.unbind_s() self.conn.unbind_s()
except: except:
raise YunoHostError(169, _('An error occured during disconnection')) raise YunoHostError(169, _('An error occured during disconnection'))