Skip to content

Commit

Permalink
Merge pull request #135 from dariusstefan/python-opensips
Browse files Browse the repository at this point in the history
Python opensips
  • Loading branch information
razvancrainea authored Nov 12, 2024
2 parents 0f8bae9 + 314766c commit 0e6d199
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 353 deletions.
2 changes: 2 additions & 0 deletions opensipscli/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@ class OpenSIPSCLIArgs:
Class that contains the default values of CLI Arguments
"""
debug = False
print = False
execute = True
command = []
config = None
instance = defaults.DEFAULT_SECTION
extra_options = {}

__fields__ = ['debug',
'print',
'execute',
'command',
'config',
Expand Down
4 changes: 4 additions & 0 deletions opensipscli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(self, options = None):
options = args.OpenSIPSCLIArgs()

self.debug = options.debug
self.print = options.print
self.execute = options.execute
self.command = options.command
self.modules_dir_inserted = None
Expand Down Expand Up @@ -89,6 +90,9 @@ def __init__(self, options = None):
# Opening the current working instance
self.update_instance(cfg.current_instance)

if self.print:
logger.info(f"Config:\n" + "\n".join([f"{k}: {v}" for k, v in cfg.to_dict().items()]))

def update_logger(self):
"""
alter logging level
Expand Down
17 changes: 3 additions & 14 deletions opensipscli/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,25 @@

from opensipscli.logger import logger
from opensipscli.config import cfg
from opensipscli import communication
from opensips.mi import OpenSIPSMI, OpenSIPSMIException

comm_handler = None
comm_handler_valid = None

def initialize():
global comm_handler
comm_type = cfg.get('communication_type')
comm_func = 'opensipscli.communication.{}'.format(comm_type)
try:
comm_handler = __import__(comm_func, fromlist=[comm_type])
except ImportError as ie:
comm_handler = None
logger.error("cannot import '{}' handler: {}"
.format(comm_type, ie))
comm_handler = OpenSIPSMI(comm_type, **cfg.to_dict())
valid()

def execute(cmd, params=[], silent=False):
global comm_handler
try:
ret = comm_handler.execute(cmd, params)
except communication.jsonrpc_helper.JSONRPCError as ex:
except OpenSIPSMIException as ex:
if not silent:
logger.error("command '{}' returned: {}".format(cmd, ex))
return None
except communication.jsonrpc_helper.JSONRPCException as ex:
if not silent:
logger.error("communication exception for '{}' returned: {}".format(cmd, ex))
logger.error("Is OpenSIPS running?")
return None
return ret

def valid():
Expand Down
22 changes: 0 additions & 22 deletions opensipscli/communication/__init__.py

This file was deleted.

42 changes: 0 additions & 42 deletions opensipscli/communication/datagram.py

This file was deleted.

135 changes: 0 additions & 135 deletions opensipscli/communication/fifo.py

This file was deleted.

64 changes: 0 additions & 64 deletions opensipscli/communication/http.py

This file was deleted.

Loading

0 comments on commit 0e6d199

Please sign in to comment.