Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
La Quadrature du Net
piphone
piphone-sip
Commits
871154d1
Commit
871154d1
authored
May 04, 2016
by
okhin
Browse files
Adding a clean arg parser and usage message
parent
9a648dd3
Pipeline
#25
skipped
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
app.py
View file @
871154d1
...
...
@@ -10,6 +10,8 @@ import asyncio
import
re
import
configparser
import
argparse
import
os.path
import
sys
from
operator
import
itemgetter
import
jwt
...
...
@@ -17,8 +19,9 @@ import websockets
import
requests
from
bottle
import
request
,
abort
,
Bottle
,
JSONPlugin
from
bottle_sqlite
import
SQLitePlugin
from
daemonize
import
Daemonize
config
=
ConfigParser
()
config
=
configparser
.
ConfigParser
()
application
=
app
=
Bottle
(
autojson
=
False
)
app
.
install
(
SQLitePlugin
(
dbfile
=
'call.db'
))
app
.
install
(
JSONPlugin
(
json_dumps
=
lambda
s
:
json
.
dumps
(
s
,
cls
=
PiphoneJSONEncoder
)))
...
...
@@ -361,12 +364,19 @@ class Call(object):
phone_logger
.
exception
(
e
)
raise
e
def
start
():
global
running
running
=
True
threads
.
submit
(
app
.
run
)
loop
.
run_until_complete
(
listen
())
def
stop
():
global
running
running
=
False
ws
.
close
()
loop
.
close
()
threads
.
shutdown
(
wait
=
False
)
sys
.
exit
(
0
)
@
app
.
get
(
'/calls/<callid>'
)
@
app
.
get
(
'/calls/'
)
...
...
@@ -432,14 +442,27 @@ def originate(db, callid=None):
abort
(
400
,
"Missing or incorrect fields, the call cannot be processed"
)
if
__name__
==
'__main__'
:
global
config
arg_parser
=
argparse
.
ArgumentParser
(
description
=
'Manage the SIP Backend for the piphone'
)
arg_parser
.
add_argument
(
'-c'
,
'--config'
,
help
=
"Config file"
)
arg_parser
.
parse_args
()
config
=
ConfigParser
(
arg_parser
.
config
)
try
:
running
=
True
threads
.
submit
(
app
.
run
)
loop
.
run_until_complete
(
listen
())
logging
.
debug
(
"Let's use {} as a config file"
.
config
(
arg_parser
.
config
,))
config
.
read
(
arg_parser
.
config
)
except
AttributeError
:
try
:
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'
):
logging
.
debug
(
"Let's use /etc/iphone/config.ini as a config file"
)
config
.
read
(
'/etc/piphone/config.ini'
)
else
:
raise
Exception
(
"No configuration file found (tried ./config.ini and /etc/piphone/config.ini"
)
except
Exception
as
e
:
phone_logger
.
error
(
"Config file cannot be read"
)
arg_parser
.
print_help
()
sys
.
exit
(
1
)
try
:
start
()
except
:
stop
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment