mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
nested levels
This commit is contained in:
parent
428ea27e34
commit
e57bb88717
1 changed files with 9 additions and 1 deletions
10
yunohost.py
10
yunohost.py
|
@ -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'))
|
||||||
|
|
Loading…
Add table
Reference in a new issue