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
class NullRecv(EnvironmentError):
pass
class AsteriskError(ValueError):
pass
class Profile(object):
def __init__(self, sql_params, database):
self.sql_params = sql_params
......@@ -177,7 +180,7 @@ class Manager(object):
self._event=[]
self._event_callback = {}
self._toread = ""
self.privilege = []
self.fullybooted = False
self.username = username
self.password = password
......@@ -187,7 +190,7 @@ class Manager(object):
self.connect()
def _FullyBooted(self, manager, params):
manager.privilege = params['Privilege'].split(',')
manager.fullybooted = True
def _recv(self):
data = self.socket.recv(1024)
......@@ -244,7 +247,7 @@ class Manager(object):
del(self._response[id])
self._pending_action.remove(id)
if response[0] == 'Error':
raise ValueError(response)
raise AsteriskError('%s. Action:%s params:%s' % (response[1]['Message'], name, params))
return response
def action(self, name, **params):
......@@ -260,7 +263,8 @@ class Manager(object):
if len(msg)>1:
self._toread += msg[1]
self.login()
self.process_events()
while not self.fullybooted:
self.process_events()
self.events(self.event)
def register_events_callback(self, event, func):
......@@ -285,7 +289,9 @@ class Manager(object):
def logoff(self):
""" Logoff Manager"""
self.action('logoff')
response = self.action('logoff')
if response[0] == 'Goodbye':
self.fullybooted = False
def events(self, param):
"""Control Event Flow
......
......@@ -26,7 +26,7 @@ def reload_config(config):
manager.connect()
for module in reload_srv[config]:
try:manager.reload(module)
except ValueError: pass
except asterisk.AsteriskError: pass
manager.logoff()
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