Commit 7651da65 authored by okhin's avatar okhin 🚴

Moving back to python3.4

parent 673d1d12
Pipeline #72 failed
......@@ -2,10 +2,11 @@ before_script:
- '[[ -d /srv/piphone/ ]] || mkdir -p /srv/piphone/'
- 'which git || (apt-get update -yq && apt-get install git -yqq)'
- 'which virtualenv || (apt-get update -yq && apt-get install python3-virtualenv -yqq)'
stages:
- install
- '[[ which sqlite3 || (apt-get update -yq && apt-get install sqlite3 -yqq)'
job install:
variables:
SQLITE_DB: "/srv/piphone/backend_sip.sqlite3"
script:
- chmod a+x ci/install.sh
- ./ci/install.sh
......
......@@ -31,3 +31,8 @@ then
fi
source .${CI_PROJECT_NAME}_env/bin/activate
pip install -r ./requirements.txt
if [ ! -e $SQLITE_DB ]
then
sqlite3 $SQLITE_DB < database.sql
fi
......@@ -34,11 +34,11 @@ except AttributeError:
if os.path.isfile('config.ini'):
logging.debug("Let's use config.ini as a config file")
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")
config.read('/etc/piphone/config.ini')
config.read('/etc/piphone/sip_config.ini')
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:
arg_parser.print_help()
sys.exit(1)
......@@ -145,7 +145,8 @@ def sanitize_phonenumber(number):
raise TypeError('{} is not a valid international number, it should start with 00')
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.
It will play a song in a loop.
......@@ -164,22 +165,23 @@ async def hold_bridge():
phone_logger.exception(e)
raise e
async def listen():
@asyncio.coroutine
def listen():
'''
Start listening on the websocket
'''
global running
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 = 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']))
ws_logger.debug('Websocket connected: {}'.format(type(ws)))
await hold_bridge()
yield from hold_bridge()
while running == True:
try:
event = await ws.recv()
event = yield from ws.recv()
# Let's call the applications function
await dispatch(json.loads(event))
yield from dispatch(json.loads(event))
except websockets.exceptions.ConnectionClosed as e:
ws_logger.warning("Connexion closed")
ws_logger.exception(e)
......@@ -191,7 +193,8 @@ async def listen():
continue
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
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