Commit 7651da65 authored by okhin's avatar okhin 🚴

Moving back to python3.4

parent 673d1d12
Pipeline #72 failed
...@@ -2,10 +2,11 @@ before_script: ...@@ -2,10 +2,11 @@ before_script:
- '[[ -d /srv/piphone/ ]] || mkdir -p /srv/piphone/' - '[[ -d /srv/piphone/ ]] || mkdir -p /srv/piphone/'
- 'which git || (apt-get update -yq && apt-get install git -yqq)' - 'which git || (apt-get update -yq && apt-get install git -yqq)'
- 'which virtualenv || (apt-get update -yq && apt-get install python3-virtualenv -yqq)' - 'which virtualenv || (apt-get update -yq && apt-get install python3-virtualenv -yqq)'
stages: - '[[ which sqlite3 || (apt-get update -yq && apt-get install sqlite3 -yqq)'
- install
job install: job install:
variables:
SQLITE_DB: "/srv/piphone/backend_sip.sqlite3"
script: script:
- chmod a+x ci/install.sh - chmod a+x ci/install.sh
- ./ci/install.sh - ./ci/install.sh
......
...@@ -31,3 +31,8 @@ then ...@@ -31,3 +31,8 @@ then
fi fi
source .${CI_PROJECT_NAME}_env/bin/activate source .${CI_PROJECT_NAME}_env/bin/activate
pip install -r ./requirements.txt pip install -r ./requirements.txt
if [ ! -e $SQLITE_DB ]
then
sqlite3 $SQLITE_DB < database.sql
fi
...@@ -34,11 +34,11 @@ except AttributeError: ...@@ -34,11 +34,11 @@ except AttributeError:
if os.path.isfile('config.ini'): if os.path.isfile('config.ini'):
logging.debug("Let's use config.ini as a config file") logging.debug("Let's use config.ini as a config file")
config.read('config.ini') config.read('config.ini')
elif os.path.isfile('/etc/piphone/config.ini'): elif os.path.isfile('/etc/piphone/sip_config.ini'):
logging.debug("Let's use /etc/iphone/config.ini as a config file") logging.debug("Let's use /etc/iphone/config.ini as a config file")
config.read('/etc/piphone/config.ini') config.read('/etc/piphone/sip_config.ini')
else: else:
raise Exception("No configuration file found (tried ./config.ini and /etc/piphone/config.ini") raise Exception("No configuration file found (tried ./config.ini and /etc/piphone/sip_config.ini")
except Exception as e: except Exception as e:
arg_parser.print_help() arg_parser.print_help()
sys.exit(1) sys.exit(1)
...@@ -145,7 +145,8 @@ def sanitize_phonenumber(number): ...@@ -145,7 +145,8 @@ def sanitize_phonenumber(number):
raise TypeError('{} is not a valid international number, it should start with 00') raise TypeError('{} is not a valid international number, it should start with 00')
return number return number
async def hold_bridge(): @asyncio.coroutine
def hold_bridge():
''' '''
We will create a bridge that will be used to park caller waiting for callee to join. We will create a bridge that will be used to park caller waiting for callee to join.
It will play a song in a loop. It will play a song in a loop.
...@@ -164,22 +165,23 @@ async def hold_bridge(): ...@@ -164,22 +165,23 @@ async def hold_bridge():
phone_logger.exception(e) phone_logger.exception(e)
raise e raise e
async def listen(): @asyncio.coroutine
def listen():
''' '''
Start listening on the websocket Start listening on the websocket
''' '''
global running global running
global ws global ws
ws_logger.debug('Connecting to websocket: {}'.format(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format(config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password']))) ws_logger.debug('Connecting to websocket: {}'.format(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format(config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password'])))
ws = await websockets.connect(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format( ws = yield from websockets.connect(config['webservice']['base_url'] + '?app={}&api_key={}:{}'.format(
config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password'])) config['asterisk']['app'], config['asterisk']['key'], config['asterisk']['password']))
ws_logger.debug('Websocket connected: {}'.format(type(ws))) ws_logger.debug('Websocket connected: {}'.format(type(ws)))
await hold_bridge() yield from hold_bridge()
while running == True: while running == True:
try: try:
event = await ws.recv() event = yield from ws.recv()
# Let's call the applications function # Let's call the applications function
await dispatch(json.loads(event)) yield from dispatch(json.loads(event))
except websockets.exceptions.ConnectionClosed as e: except websockets.exceptions.ConnectionClosed as e:
ws_logger.warning("Connexion closed") ws_logger.warning("Connexion closed")
ws_logger.exception(e) ws_logger.exception(e)
...@@ -191,7 +193,8 @@ async def listen(): ...@@ -191,7 +193,8 @@ async def listen():
continue continue
ws.close() ws.close()
async def dispatch(self, event): @asyncio.coroutine
def dispatch(self, event):
""" """
Let's work on our events. Parse them and do request on the ARI API. Event is Let's work on our events. Parse them and do request on the ARI API. Event is
a dict loaded from JSON. a dict loaded from JSON.
......
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