Commit e1019a34 authored by Valentin Samir's avatar Valentin Samir

[sip] Utilisation d'erreur custom

parent a7a732ab
...@@ -19,6 +19,9 @@ import lc_ldap.shortcuts ...@@ -19,6 +19,9 @@ import lc_ldap.shortcuts
class NullRecv(EnvironmentError): class NullRecv(EnvironmentError):
pass pass
class AsteriskError(ValueError):
pass
class Profile(object): class Profile(object):
def __init__(self, sql_params, database): def __init__(self, sql_params, database):
self.sql_params = sql_params self.sql_params = sql_params
...@@ -177,7 +180,7 @@ class Manager(object): ...@@ -177,7 +180,7 @@ class Manager(object):
self._event=[] self._event=[]
self._event_callback = {} self._event_callback = {}
self._toread = "" self._toread = ""
self.privilege = [] self.fullybooted = False
self.username = username self.username = username
self.password = password self.password = password
...@@ -187,7 +190,7 @@ class Manager(object): ...@@ -187,7 +190,7 @@ class Manager(object):
self.connect() self.connect()
def _FullyBooted(self, manager, params): def _FullyBooted(self, manager, params):
manager.privilege = params['Privilege'].split(',') manager.fullybooted = True
def _recv(self): def _recv(self):
data = self.socket.recv(1024) data = self.socket.recv(1024)
...@@ -244,7 +247,7 @@ class Manager(object): ...@@ -244,7 +247,7 @@ class Manager(object):
del(self._response[id]) del(self._response[id])
self._pending_action.remove(id) self._pending_action.remove(id)
if response[0] == 'Error': if response[0] == 'Error':
raise ValueError(response) raise AsteriskError('%s. Action:%s params:%s' % (response[1]['Message'], name, params))
return response return response
def action(self, name, **params): def action(self, name, **params):
...@@ -260,7 +263,8 @@ class Manager(object): ...@@ -260,7 +263,8 @@ class Manager(object):
if len(msg)>1: if len(msg)>1:
self._toread += msg[1] self._toread += msg[1]
self.login() self.login()
self.process_events() while not self.fullybooted:
self.process_events()
self.events(self.event) self.events(self.event)
def register_events_callback(self, event, func): def register_events_callback(self, event, func):
...@@ -285,7 +289,9 @@ class Manager(object): ...@@ -285,7 +289,9 @@ class Manager(object):
def logoff(self): def logoff(self):
""" Logoff Manager""" """ Logoff Manager"""
self.action('logoff') response = self.action('logoff')
if response[0] == 'Goodbye':
self.fullybooted = False
def events(self, param): def events(self, param):
"""Control Event Flow """Control Event Flow
......
...@@ -26,7 +26,7 @@ def reload_config(config): ...@@ -26,7 +26,7 @@ def reload_config(config):
manager.connect() manager.connect()
for module in reload_srv[config]: for module in reload_srv[config]:
try:manager.reload(module) try:manager.reload(module)
except ValueError: pass except asterisk.AsteriskError: pass
manager.logoff() manager.logoff()
if __name__ == '__main__' : if __name__ == '__main__' :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment