misc of python pep8 fixes

This commit is contained in:
areski 2014-07-03 13:46:56 +02:00
parent 39200cd13b
commit b0e86e65cf
5 changed files with 98 additions and 100 deletions

View File

@ -31,6 +31,7 @@ from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientFactory from twisted.internet.protocol import ClientFactory
import freepy import freepy
class FsHelper(ClientFactory): class FsHelper(ClientFactory):
def __init__(self, host=None, passwd=None, port=None): def __init__(self, host=None, passwd=None, port=None):
@ -72,7 +73,6 @@ class FsHelper(ClientFactory):
self.connection_deferred = None self.connection_deferred = None
deferred2callback.callback("Connected") deferred2callback.callback("Connected")
def generalError(self, failure): def generalError(self, failure):
print "General error: %s" % failure print "General error: %s" % failure
return failure return failure
@ -128,9 +128,6 @@ class FsHelper(ClientFactory):
d.addCallback(originate_inner) d.addCallback(originate_inner)
return d return d
def dialconf(self, people2dial, conf_name, bgapi=True): def dialconf(self, people2dial, conf_name, bgapi=True):
""" """
conf_name - name of conf TODO: change to match db conf_name - name of conf TODO: change to match db
@ -215,7 +212,6 @@ class FsHelper(ClientFactory):
d.addCallback(confdtmf_inner) d.addCallback(confdtmf_inner)
return d return d
def confsay(self, conf_name, text2speak, bgapi=True): def confsay(self, conf_name, text2speak, bgapi=True):
""" """
conf_name - name of conf conf_name - name of conf
@ -268,7 +264,6 @@ class FsHelper(ClientFactory):
d.addCallback(confstop_inner) d.addCallback(confstop_inner)
return d return d
def showchannels(self, bgapi=True): def showchannels(self, bgapi=True):
def showchannels_inner(ignored): def showchannels_inner(ignored):
@ -289,7 +284,6 @@ class FsHelper(ClientFactory):
d.addCallback(killchan_inner) d.addCallback(killchan_inner)
return d return d
def broadcast(self, uuid, path, legs="both", bgapi=True): def broadcast(self, uuid, path, legs="both", bgapi=True):
""" """
@legs - one of the following strings: aleg|bleg|both @legs - one of the following strings: aleg|bleg|both
@ -325,12 +319,10 @@ class FsHelper(ClientFactory):
d.addCallback(sofia_profile_restart_inner) d.addCallback(sofia_profile_restart_inner)
return d return d
def sofia_status_profile(self, profile_name, bgapi=True): def sofia_status_profile(self, profile_name, bgapi=True):
def sofia_status_profile_inner(ignored): def sofia_status_profile_inner(ignored):
df = self.freepyd.sofia_status_profile(profile_name, df = self.freepyd.sofia_status_profile(profile_name, bgapi)
bgapi)
return df return df
d = self.connect() d = self.connect()
@ -340,7 +332,7 @@ class FsHelper(ClientFactory):
class FsHelperTest: class FsHelperTest:
def __init__(self, fshelper): def __init__(self, fshelper):
self.fshelper=fshelper self.fshelper = fshelper
pass pass
def test_dialconf(self): def test_dialconf(self):
@ -349,10 +341,16 @@ class FsHelperTest:
# called "freeswitch" on the local freeswitch instance. # called "freeswitch" on the local freeswitch instance.
# one party is actually another conference, just to make # one party is actually another conference, just to make
# the example more confusing. # the example more confusing.
people2dial = [{'name':'freeswitch', people2dial = [
'number':'888@conference.freeswitch.org'}, {
{'name':'mouselike', 'name': 'freeswitch',
'number':'904@mouselike.org'}] 'number': '888@conference.freeswitch.org'
},
{
'name': 'mouselike',
'number': ' 904@mouselike.org'
}
]
d = self.fshelper.dialconf(people2dial, "freeswitch", bgapi=False) d = self.fshelper.dialconf(people2dial, "freeswitch", bgapi=False)
def failed(error): def failed(error):
print "Failed to dial users!" print "Failed to dial users!"
@ -494,8 +492,7 @@ def test5():
#reactor.stop() #reactor.stop()
for i in xrange(20): for i in xrange(20):
party2dial = "sofia/foo/600@192.168.1.202:5080"
party2dial="sofia/foo/600@192.168.1.202:5080"
d = fshelper.originate(party2dial=party2dial, d = fshelper.originate(party2dial=party2dial,
dest_ext_app="700", dest_ext_app="700",
bgapi=True) bgapi=True)
@ -504,6 +501,7 @@ def test5():
reactor.run() reactor.run()
def test6(): def test6():
""" """
show channels for a given sofia profile show channels for a given sofia profile
@ -524,7 +522,7 @@ def test6():
reactor.run() reactor.run()
if __name__=="__main__": if __name__ == "__main__":
#test1() #test1()
#test2() #test2()
#test3() #test3()

View File

@ -30,6 +30,7 @@ Data models for objects inside freeswitch
import re import re
class ConfMember: class ConfMember:
def __init__(self, rawstring): def __init__(self, rawstring):

View File

@ -2,11 +2,11 @@
# http://wiki.freeswitch.org/wiki/Mod_python # http://wiki.freeswitch.org/wiki/Mod_python
# before reporting errors # before reporting errors
import sys, time
from freeswitch import * from freeswitch import *
def onDTMF(input, itype, funcargs): def onDTMF(input, itype, funcargs):
console_log("1","\n\nonDTMF input: %s\n" % input) console_log("1", "\n\nonDTMF input: %s\n" % input)
if input == "5": if input == "5":
return "pause" return "pause"
if input == "3": if input == "3":
@ -17,9 +17,9 @@ def onDTMF(input, itype, funcargs):
return "stop" return "stop"
return None # will make the streamfile audio stop return None # will make the streamfile audio stop
def handler(uuid):
console_log("1","... test from my python program\n") def handler(uuid):
console_log("1", "... test from my python program\n")
session = PySession(uuid) session = PySession(uuid)
session.answer() session.answer()
session.setDTMFCallback(onDTMF, "") session.setDTMFCallback(onDTMF, "")
@ -27,13 +27,12 @@ def handler(uuid):
session.playFile("/path/to/your.mp3", "") session.playFile("/path/to/your.mp3", "")
session.speak("Please enter telephone number with area code and press pound sign. ") session.speak("Please enter telephone number with area code and press pound sign. ")
input = session.getDigits("", 11, "*#", "#", 10000) input = session.getDigits("", 11, "*#", "#", 10000)
console_log("1","result from get digits is %s\n" % input) console_log("1", "result from get digits is %s\n" % input)
phone_number = session.playAndGetDigits(5, 11, 3, 10000, "*#", phone_number = session.playAndGetDigits(5, 11, 3, 10000, "*#",
"/sounds/test.gsm", "/sounds/test.gsm",
"/sounds/invalid.gsm", "/sounds/invalid.gsm",
"", "",
"^17771112222$"); "^17771112222$")
console_log("1","result from play_and_get_digits is %s\n" % phone_number) console_log("1", "result from play_and_get_digits is %s\n" % phone_number)
session.transfer("1000", "XML", "default") session.transfer("1000", "XML", "default")
session.hangup("1") session.hangup("1")

View File

@ -2,7 +2,7 @@ from freeswitch import *
from py_modules.speechtools import Grammar, SpeechDetect from py_modules.speechtools import Grammar, SpeechDetect
from py_modules.speechtools import SpeechObtainer from py_modules.speechtools import SpeechObtainer
import time, os import os
VOICE_ENGINE = "cepstral" VOICE_ENGINE = "cepstral"
VOICE = "William" VOICE = "William"
@ -20,24 +20,24 @@ How to make this work:
""" """
class RecipeWizard: class RecipeWizard:
def __init__(self, session): def __init__(self, session):
self.session=session self.session = session
self.session.set_tts_parms(VOICE_ENGINE, VOICE) self.session.set_tts_parms(VOICE_ENGINE, VOICE)
self.main() self.main()
def main(self): def main(self):
console_log("debug", "recipe wizard main()\n") console_log("debug", "recipe wizard main()\n")
self.speechdetect = SpeechDetect(self.session, "openmrcp", "127.0.0.1"); self.speechdetect = SpeechDetect(self.session, "openmrcp", "127.0.0.1")
self.speechobtainer = SpeechObtainer(speech_detect=self.speechdetect, self.speechobtainer = SpeechObtainer(speech_detect=self.speechdetect,
required_phrases=1, required_phrases=1,
wait_time=5000, wait_time=5000,
max_tries=3) max_tries=3)
gfile = os.path.join(GRAMMAR_ROOT, "mainmenu.xml") gfile = os.path.join(GRAMMAR_ROOT, "mainmenu.xml")
self.grammar = Grammar("mainmenu", gfile,"input",80,90) self.grammar = Grammar("mainmenu", gfile, "input", 80, 90)
self.speechobtainer.setGrammar(self.grammar); self.speechobtainer.setGrammar(self.grammar)
console_log("debug", "calling speechobtainer.run()\n") console_log("debug", "calling speechobtainer.run()\n")
self.speechobtainer.detectSpeech() self.speechobtainer.detectSpeech()
self.session.speak("Hello. Welcome to the recipe wizard. Drinks or food?") self.session.speak("Hello. Welcome to the recipe wizard. Drinks or food?")
@ -50,6 +50,7 @@ class RecipeWizard:
console_log("debug", "speechobtainer.run() finished\n") console_log("debug", "speechobtainer.run() finished\n")
def mainmenu(): def mainmenu():
""" """
<!DOCTYPE grammar PUBLIC "-//W3C//DTD GRAMMAR 1.0//EN" <!DOCTYPE grammar PUBLIC "-//W3C//DTD GRAMMAR 1.0//EN"
@ -78,10 +79,9 @@ def mainmenu():
""" """
pass pass
def handler(uuid): def handler(uuid):
session = PySession(uuid) session = PySession(uuid)
session.answer() session.answer()
rw = RecipeWizard(session) rw = RecipeWizard(session)
session.hangup("1") session.hangup("1")