Skip to content

Commit 0e6d199

Browse files
Merge pull request #135 from dariusstefan/python-opensips
Python opensips
2 parents 0f8bae9 + 314766c commit 0e6d199

File tree

11 files changed

+25
-353
lines changed

11 files changed

+25
-353
lines changed

opensipscli/args.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ class OpenSIPSCLIArgs:
2929
Class that contains the default values of CLI Arguments
3030
"""
3131
debug = False
32+
print = False
3233
execute = True
3334
command = []
3435
config = None
3536
instance = defaults.DEFAULT_SECTION
3637
extra_options = {}
3738

3839
__fields__ = ['debug',
40+
'print',
3941
'execute',
4042
'command',
4143
'config',

opensipscli/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(self, options = None):
4848
options = args.OpenSIPSCLIArgs()
4949

5050
self.debug = options.debug
51+
self.print = options.print
5152
self.execute = options.execute
5253
self.command = options.command
5354
self.modules_dir_inserted = None
@@ -89,6 +90,9 @@ def __init__(self, options = None):
8990
# Opening the current working instance
9091
self.update_instance(cfg.current_instance)
9192

93+
if self.print:
94+
logger.info(f"Config:\n" + "\n".join([f"{k}: {v}" for k, v in cfg.to_dict().items()]))
95+
9296
def update_logger(self):
9397
"""
9498
alter logging level

opensipscli/comm.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,36 +19,25 @@
1919

2020
from opensipscli.logger import logger
2121
from opensipscli.config import cfg
22-
from opensipscli import communication
22+
from opensips.mi import OpenSIPSMI, OpenSIPSMIException
2323

2424
comm_handler = None
2525
comm_handler_valid = None
2626

2727
def initialize():
2828
global comm_handler
2929
comm_type = cfg.get('communication_type')
30-
comm_func = 'opensipscli.communication.{}'.format(comm_type)
31-
try:
32-
comm_handler = __import__(comm_func, fromlist=[comm_type])
33-
except ImportError as ie:
34-
comm_handler = None
35-
logger.error("cannot import '{}' handler: {}"
36-
.format(comm_type, ie))
30+
comm_handler = OpenSIPSMI(comm_type, **cfg.to_dict())
3731
valid()
3832

3933
def execute(cmd, params=[], silent=False):
4034
global comm_handler
4135
try:
4236
ret = comm_handler.execute(cmd, params)
43-
except communication.jsonrpc_helper.JSONRPCError as ex:
37+
except OpenSIPSMIException as ex:
4438
if not silent:
4539
logger.error("command '{}' returned: {}".format(cmd, ex))
4640
return None
47-
except communication.jsonrpc_helper.JSONRPCException as ex:
48-
if not silent:
49-
logger.error("communication exception for '{}' returned: {}".format(cmd, ex))
50-
logger.error("Is OpenSIPS running?")
51-
return None
5241
return ret
5342

5443
def valid():

opensipscli/communication/__init__.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

opensipscli/communication/datagram.py

Lines changed: 0 additions & 42 deletions
This file was deleted.

opensipscli/communication/fifo.py

Lines changed: 0 additions & 135 deletions
This file was deleted.

opensipscli/communication/http.py

Lines changed: 0 additions & 64 deletions
This file was deleted.

0 commit comments

Comments
 (0)