aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVadim Yanitskiy <axilirator@gmail.com>2018-09-30 17:03:49 +0700
committerVadim Yanitskiy <axilirator@gmail.com>2018-09-30 17:21:41 +0700
commitaf9a227a898b57dc3aac5473113bb99fac1279fe (patch)
tree8aa67b03d583c756e0d81365023ca934d388ee5e
parent8b5c864f28bb21235a04b088f8da61fb5b2f1c9d (diff)
*.py: use generic logging framework instead of print()
-rw-r--r--contrib/manual_test_server.py16
-rw-r--r--gsm_call_fsm.py15
-rw-r--r--mncc_sock.py7
-rwxr-xr-xmncc_test.py10
-rwxr-xr-xsmpp_test.py4
5 files changed, 28 insertions, 24 deletions
diff --git a/contrib/manual_test_server.py b/contrib/manual_test_server.py
index 7338129..4b2b5bd 100644
--- a/contrib/manual_test_server.py
+++ b/contrib/manual_test_server.py
@@ -91,39 +91,39 @@ conn = server.accept()
# Say hello and set-up a call
conn.send_msg(MnccMessageBuilder.build_hello())
conn.send_msg(MnccMessageBuilder.build_setup_ind("1234", "5000"))
-print("=> Sent hello + setup indication")
+log.info("=> Sent hello + setup indication")
# Wait for the RTP crate.. and actknowledge it..
msg = conn.recv()
assert msg.msg_type == mncc.MNCC_RTP_CREATE
-print("<= Received request to create a RTP socket")
+log.info("<= Received request to create a RTP socket")
conn.send_msg(MnccMessageBuilder.build_rtp_msg(mncc.MNCC_RTP_CREATE,
msg.callref,
#socket.INADDR_LOOPBACK, 4000))
socket.INADDR_ANY, 4000))
-print("=> Claimed socket was created...")
+log.info("=> Claimed socket was created...")
msg = conn.recv()
assert msg.msg_type == mncc.MNCC_CALL_PROC_REQ
-print("<= Received proceeding...")
+log.info("<= Received proceeding...")
while True:
msg = conn.recv()
if msg.msg_type == mncc.MNCC_ALERT_REQ:
- print("=> I should alert...")
+ log.info("=> I should alert...")
continue
if msg.msg_type == mncc.MNCC_RTP_CONNECT:
conn.send_msg(MnccMessageBuilder.build_rtp_msg(mncc.MNCC_RTP_CONNECT,
msg.callref,
socket.INADDR_LOOPBACK, 4000))
- print("=> I needed to connect RTP...")
+ log.info("=> I needed to connect RTP...")
continue
if msg.msg_type == mncc.MNCC_SETUP_RSP:
- print("=> Call is connected?")
+ log.info("=> Call is connected?")
conn.send_msg(MnccMessageBuilder.build_setup_cmpl_ind(msg.callref))
send_dtmf(msg.callref)
continue
- print(msg)
+ log.debug(msg)
diff --git a/gsm_call_fsm.py b/gsm_call_fsm.py
index c62df0c..a9ad8c0 100644
--- a/gsm_call_fsm.py
+++ b/gsm_call_fsm.py
@@ -13,6 +13,8 @@ import mncc
import ctypes
import pykka
+import logging as log
+
from fysom import Fysom
from mncc_sock import mncc_msg, mncc_number, mncc_rtp_msg, mncc_bridge_msg, mncc_bearer_cap
@@ -76,7 +78,7 @@ class GsmCallFsm(pykka.ThreadingActor):
return GsmCallFsm.last_callref;
def _printstatechange(self, e):
- print '%s: event: %s, %s -> %s' % (self, e.event, e.src, e.dst)
+ log.debug('%s: event: %s, %s -> %s' % (self, e.event, e.src, e.dst))
if self.ctrl_ref != None:
self.ctrl_ref.tell({'type':'call_state_change', 'called':self.called, 'old_state':e.src, 'new_state':e.dst})
@@ -98,7 +100,7 @@ class GsmCallFsm(pykka.ThreadingActor):
def _onmncc_call_conf_ind(self, e):
msg_in = e.args[0]
codec = self.find_matching_codec(msg_in.bearer_cap.speech_ver)
- print '%s: CALL-CONF.ind(selected codec = %s)' % (self, codec)
+ log.info('%s: CALL-CONF.ind(selected codec = %s)' % (self, codec))
# select the according lchan_mode
lchan_mode = codec.to_lchan_mode()
msg = mncc_msg(msg_type = mncc.MNCC_LCHAN_MODIFY, callref = msg_in.callref, lchan_mode = lchan_mode)
@@ -292,7 +294,7 @@ class GsmCallFsm(pykka.ThreadingActor):
if message['type'] == 'mncc':
msg = message['msg']
if msg.callref == self.callref:
- print '%s: on_receive(mncc, %s)' % (self, msg)
+ log.debug('%s: on_receive(mncc, %s)' % (self, msg))
return self._handle_mncc(msg)
elif message['type'] == 'start_mt_call':
self.start_mt_call(message['calling'], message['called'])
@@ -326,7 +328,7 @@ class GsmCallConnector(pykka.ThreadingActor):
self.call_b.tell({'type':'start_mt_call', 'calling':self.msisdn_a, 'called':self.msisdn_b})
def rtp_created(self, msisdn, rtp):
- print 'CallConnector:rtp_created(%s) %s' % (msisdn, rtp)
+ log.info('CallConnector:rtp_created(%s) %s' % (msisdn, rtp))
if self.rtp_bridge == False:
raise Exception('GsmCallConnector', 'rtp_created but not in RTP bridge mode')
if msisdn == self.msisdn_a: # A->B leg
@@ -345,7 +347,8 @@ class GsmCallConnector(pykka.ThreadingActor):
self.mncc_act.tell({'type': 'send', 'msg': msg})
def call_state_change(self, msisdn, old_state, new_state):
- print 'CallConnector:leg_state_change(%s) %s -> %s' % (msisdn, old_state, new_state)
+ log.debug('CallConnector:leg_state_change(%s) %s -> %s'
+ % (msisdn, old_state, new_state))
if msisdn == self.msisdn_a: # A->B leg
self.state_a = new_state
elif msisdn == self.msisdn_b: # B->A leg
@@ -353,7 +356,7 @@ class GsmCallConnector(pykka.ThreadingActor):
if self.rtp_bridge == False and self.state_a == 'ACTIVE' and self.state_b == 'ACTIVE':
self.bridge_legs()
if self.state_a == 'NULL' and self.state_b == 'NULL':
- print 'Both A and B in state NULL -> Terminating'
+ log.info('Both A and B in state NULL -> Terminating')
self.stop()
def on_receive(self, message):
diff --git a/mncc_sock.py b/mncc_sock.py
index 0a64a81..009a476 100644
--- a/mncc_sock.py
+++ b/mncc_sock.py
@@ -9,6 +9,7 @@
# Licensed under GNU General Public License, Version 2 or at your
# option, any later version.
+import logging as log
import socket
import os
import mncc
@@ -120,14 +121,14 @@ class MnccSocket(MnccSocketBase):
def __init__(self, address = '/tmp/bsc_mncc'):
super(MnccSocketBase, self).__init__()
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_SEQPACKET)
- print('connecting to %s' % address)
+ log.info('Connecting to %s' % address)
self.sock.connect(address)
# Check the HELLO message
self.check_hello()
def check_hello(self):
- print('Waiting for HELLO message...')
+ log.debug('Waiting for HELLO message...')
msg = self.recv()
# Match expected message type
@@ -149,7 +150,7 @@ class MnccSocket(MnccSocketBase):
msg.lchan_type_offset != mncc.gsm_mncc.lchan_type.offset):
raise AssertionError('MNCC message alignment mismatch\n')
- print('Received %s' % msg)
+ log.info('Received %s' % msg)
class MnccSocketServer(object):
def __init__(self, address = '/tmp/bsc_mncc'):
diff --git a/mncc_test.py b/mncc_test.py
index 9222605..508c5be 100755
--- a/mncc_test.py
+++ b/mncc_test.py
@@ -13,7 +13,7 @@ from gsm_call_fsm import GsmCallFsm, GsmCallConnector, GSM48
from mncc_sock import MnccSocket
from thread import start_new_thread
import pykka
-import logging
+import logging as log
import signal, sys, time
import readline, code
@@ -26,7 +26,7 @@ class MnccActor(pykka.ThreadingActor):
def on_receive(self, message):
if message['type'] == 'send':
msg = message['msg']
- print 'MnccActor TxMNCC %s' % msg
+ log.debug('MnccActor TxMNCC %s' % msg)
mncc_sock.send(msg)
else:
raise Exception('mncc', 'MnccActor Received unhandled %s' % message)
@@ -36,10 +36,10 @@ def mncc_rx_thread(mncc_sock):
while 1:
msg = mncc_sock.recv()
if msg.is_frame():
- print("Dropping traffic frame: %s" % msg)
+ log.warning("Dropping traffic frame: %s" % msg)
continue
- print "MnccActor RxMNCC %s, broadcasting to Call FSMs" % msg
+ log.debug("MnccActor RxMNCC %s, broadcasting to Call FSMs" % msg)
# we simply broadcast to all calls
pykka.ActorRegistry.broadcast({'type': 'mncc', 'msg': msg}, GsmCallFsm)
@@ -48,7 +48,7 @@ def sigint_handler(signum, frame):
pykka.ActorRegistry.stop_all()
sys.exit(0)
-logging.basicConfig(level = logging.DEBUG,
+log.basicConfig(level = log.DEBUG,
format = "%(levelname)s %(filename)s:%(lineno)d %(message)s")
signal.signal(signal.SIGINT, sigint_handler)
diff --git a/smpp_test.py b/smpp_test.py
index ad7d4dc..71eba91 100755
--- a/smpp_test.py
+++ b/smpp_test.py
@@ -17,7 +17,7 @@ logging.basicConfig(level = logging.DEBUG,
def send_message(dest, string):
parts, encoding_flag, msg_type_flag = smpplib.gsm.make_parts(string)
- print 'Sending SMS "%s" to %s' % (string, dest)
+ log.info('Sending SMS "%s" to %s' % (string, dest))
for part in parts:
pdu = client.send_message(
source_addr_ton=smpplib.consts.SMPP_TON_INTL,
@@ -32,7 +32,7 @@ def send_message(dest, string):
esm_class=smpplib.consts.SMPP_MSGMODE_FORWARD,
registered_delivery=False,
)
- print(pdu.sequence)
+ log.debug(pdu.sequence)
client = smpplib.client.Client('127.0.0.1', 2775)