[Freeswitch-svn] [commit] r9583 - freeswitch/trunk/scripts/socket/freepy

Freeswitch SVN greenlizard at freeswitch.org
Wed Sep 17 20:07:15 EDT 2008


Author: greenlizard
Date: Wed Sep 17 20:07:15 2008
New Revision: 9583

Modified:
   freeswitch/trunk/scripts/socket/freepy/__init__.py
   freeswitch/trunk/scripts/socket/freepy/globals.py
   freeswitch/trunk/scripts/socket/freepy/request.py

Log:
improve debuggability

Modified: freeswitch/trunk/scripts/socket/freepy/__init__.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/__init__.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/__init__.py	Wed Sep 17 20:07:15 2008
@@ -35,6 +35,7 @@
 from Queue import Queue
 from freepy import request
 import freepy.globals
+from freepy.globals import debug
 
 """
 freepy library -- connect to freeswitch mod_socket_event via python/twisted
@@ -44,6 +45,8 @@
 
 """
 
+DEBUG_ON = "see globals.py to turn on debugging"
+
 class FreepyDispatcher(LineReceiver):
 
     def __init__(self, conncb, discocb=None):
@@ -54,22 +57,14 @@
         self.active_request = None # the current active (de-queued) request
 
     def connectionMade(self):
-        self.log("Connection made")
+        debug("FREEPY: Connection made")
         self.conncb(self)
         
     def connectionLost(self, reason):
         if self.discocb:
             self.discocb(reason)        
-        self.log("connectionLost: %s" % reason)
-
+        debug("connectionLost: %s" % reason)
 
-    def log(self, msg):
-        """
-        print a message to stdout if debug enabled
-        """
-        if freepy.globals.FREEPY_DEBUG_ON:
-            print msg
-            
     def login(self, passwd):
         """
         send login request
@@ -78,7 +73,7 @@
         req = request.LoginRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)
+        debug(">> %s" % msg)
         return req.getDeferred()
 
     def confdialout(self, conf_name, sofia_url, bgapi=True):
@@ -101,7 +96,7 @@
             req = request.DialoutRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)        
+        debug(">> %s" % msg)        
         return req.getDeferred()
 
     def originate(self, party2dial, dest_ext_app, bgapi=True):
@@ -116,7 +111,7 @@
             req = request.DialoutRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                
+        debug(">> %s" % msg)                
         return req.getDeferred()
 
     def listconf(self, conf_name):
@@ -130,7 +125,7 @@
         req = request.ListConfRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                        
+        debug(">> %s" % msg)                        
         return req.getDeferred()
         
 
@@ -152,7 +147,7 @@
             req = request.ConfKickRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                        
+        debug(">> %s" % msg)                        
         return req.getDeferred()
 
     def confdtmf(self, member_id, conf_name, dtmf, bgapi=False):
@@ -176,7 +171,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                        
+        debug(">> %s" % msg)                        
         return req.getDeferred()
 
     def confsay(self, conf_name, text2speak, bgapi=False):
@@ -199,7 +194,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                                
+        debug(">> %s" % msg)                                
         return req.getDeferred()
 
     def confplay(self, conf_name, snd_url, bgapi=False):
@@ -222,7 +217,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                                        
+        debug(">> %s" % msg)                                        
         return req.getDeferred()
 
     def confstop(self, conf_name, bgapi=False):
@@ -244,7 +239,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                                        
+        debug(">> %s" % msg)                                        
         return req.getDeferred()
 
 
@@ -282,7 +277,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                                                
+        debug(">> %s" % msg)                                                
         return req.getDeferred()
 
     def sofia_status_profile(self, profile_name, bgapi=False):
@@ -295,7 +290,7 @@
             msg = "api sofia status profile %s as xml" % (profile_name)
             req = request.ApiRequest()
         self.requestq.put(req)
-        self.log("sending to fs: %s" % msg)
+        debug("sending to fs: %s" % msg)
         self.transport.write("%s\n\n" % msg)
         return req.getDeferred()
         
@@ -310,7 +305,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                                                        
+        debug(">> %s" % msg)                                                        
         return req.getDeferred()
 
 
@@ -323,7 +318,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)        
+        debug(">> %s" % msg)        
         return req.getDeferred()
 
     def broadcast(self, uuid, path, legs, bgapi = False):
@@ -335,7 +330,7 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                
+        debug(">> %s" % msg)                
         return req.getDeferred()
 
     def transfer(self, uuid, dest_ext, legs, bgapi = False):
@@ -350,11 +345,11 @@
             req = request.ApiRequest()
         self.requestq.put(req)
         self.transport.write("%s\n\n" % msg)
-        self.log(">> %s" % msg)                        
+        debug(">> %s" % msg)                        
         return req.getDeferred()
         
     def lineReceived(self, line):
-        self.log("<< %s" % line)                                
+        debug("<< %s" % line)                                
         if not self.active_request:
 
             # if no active request pending, we ignore

Modified: freeswitch/trunk/scripts/socket/freepy/globals.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/globals.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/globals.py	Wed Sep 17 20:07:15 2008
@@ -6,5 +6,9 @@
     FREEPY_DEBUG_ON = os.environ['FREEPY_DEBUG_ON']
 else:
     # fall back to hardcoded value
-    FREEPY_DEBUG_ON = False   
+    #FREEPY_DEBUG_ON = False
+    FREEPY_DEBUG_ON = True
 
+def debug(msg):
+    if FREEPY_DEBUG_ON:
+        print msg    

Modified: freeswitch/trunk/scripts/socket/freepy/request.py
==============================================================================
--- freeswitch/trunk/scripts/socket/freepy/request.py	(original)
+++ freeswitch/trunk/scripts/socket/freepy/request.py	Wed Sep 17 20:07:15 2008
@@ -37,6 +37,7 @@
 
 from freepy import models
 import freepy.globals
+from freepy.globals import debug
 
 """
 These are response handlers for different types of requests.
@@ -61,6 +62,8 @@
         return self.finished
 
     def setRequestFinished(self):
+        debug("setRequestFinished called.  response_content: %s " %
+              self.response_content)
         self.finished = True
         
     def getDeferred(self):
@@ -104,6 +107,7 @@
         matchstr = re.compile("Reply-Text", re.I)
         result = matchstr.search(line)
         if (result != None):
+            debug("FREEPY: got Reply-Text")
             fields = line.split(":") # eg, ['Reply-Text','+OK Job-UUID', '882']
             endfields = fields[1:]
             self.response_content = "".join(endfields)



More information about the Freeswitch-svn mailing list