[tuxdroid-svn] r5987 - software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/execut
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-12-16 10:21:06
|
Author: jerome
Date: 2009-12-16 11:20:53 +0100 (Wed, 16 Dec 2009)
New Revision: 5987
Modified:
software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py
Log:
* Applied new comments guideline.
Modified: software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py
===================================================================
--- software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py 2009-12-16 09:59:03 UTC (rev 5986)
+++ software_suite_v3/software/plugin/plugin-skype/branches/in_out_plugin/executables/utils.py 2009-12-16 10:20:53 UTC (rev 5987)
@@ -27,44 +27,57 @@
from string import find
from time import sleep
from threading import Thread
-
-
+
+# ==============================================================================
+# ******************************************************************************
+# MISC Class utils.
+# ******************************************************************************
+# ==============================================================================
+
+# ==============================================================================
+# Declaration of the "SkypeClient" Helper object.
+# ==============================================================================
class SkypeClient(object):
+ '''This object manage skype client basic functions.
'''
- This object manage skype client basic functions.
- '''
OnSkypeStarted = None
#Possible client values.
LINUX = 0
- WINDOWS = 1
+ WINDOWS = 1
#Client type value
client_type = -1
-
- ###################################################
- ####### Private functions ############
-
+ # ==========================================================================
+ # Private functions
+ # ==========================================================================
+
+ # --------------------------------------------------------------------------
+ # Initialize client object.
+ # --------------------------------------------------------------------------
def __init__(self, clientType):
+ '''Initialize client object.
+ @Parameter: clientType : 'LINUX' or 'WINDOWS'
'''
- Initialize client object.
- '''
self.client_type = clientType
-
+ # --------------------------------------------------------------------------
+ # Return the Skype client state.
+ # --------------------------------------------------------------------------
def __is_running_linux__(self):
+ '''Return the Skype client state.
'''
- '''
run = commands.getoutput("ps -A | grep skype")
#finding defunct to take care of zombie processes.
return ( len(run) > 0 ) and ( find( run, '<defunct>' ) == -1 )
-
+ # --------------------------------------------------------------------------
+ # Check for Skype client process.
+ # --------------------------------------------------------------------------
def __is_running_windows__(self):
+ '''Check for Skype client process.
'''
- Check for Skype client process.
- '''
try:
from win32com.client import GetObject
WMI = GetObject('winmgmts:')
@@ -73,11 +86,12 @@
except:
return False
-
+ # --------------------------------------------------------------------------
+ # Start skype on linux.
+ # --------------------------------------------------------------------------
def __start_skype_linux__(self):
+ '''Start skype on linux.
'''
- Start skype on linux.
- '''
#start skype
self.__skypeProcess = subprocess.Popen("skype", stdin = subprocess.PIPE, stdout = subprocess.PIPE)
@@ -90,12 +104,12 @@
thread = threading.Thread(target=self.OnSkypeStarted)
thread.start()
-
-
+ # --------------------------------------------------------------------------
+ # Start skype on Windows.
+ # --------------------------------------------------------------------------
def __start_skype_windows__(self):
+ '''Start skype on Windows.
'''
- Start skype on windows.
- '''
res = []
skypeDir = os.environ['PROGRAMFILES'] + '\\Skype\\Phone'
res = os.listdir(skypeDir)
@@ -112,37 +126,45 @@
thread = threading.Thread(target=self.OnSkypeStarted)
thread.start()
-
-
+ # --------------------------------------------------------------------------
+ # Stop skype on Linux.
+ # --------------------------------------------------------------------------
def __stop_skype_linux__(self):
+ '''Stop skype on Linux.
'''
- '''
cmd = "killall -15 skype 2>/dev/null"
os.system(cmd)
-
+ # --------------------------------------------------------------------------
+ # Stop skype on Windows.
+ # --------------------------------------------------------------------------
def __stop_skype_windows__(self):
+ '''Stop skype on Windows.
'''
- '''
cmd = "taskkill /IM skype.exe"
os.system(cmd)
-
- ###################################################
- ####### User functions ############
-
+ # ==========================================================================
+ # Public functions
+ # ==========================================================================
+
+ # --------------------------------------------------------------------------
+ # Return Skype client state.
+ # --------------------------------------------------------------------------
def isRunning(self):
+ '''Return Skype client state.
'''
- '''
if self.client_type == self.LINUX:
return self.__is_running_linux__()
else:
return self.__is_running_windows__()
-
+ # --------------------------------------------------------------------------
+ # Start Skype client.
+ # --------------------------------------------------------------------------
def start(self):
+ '''Start Skype client.
'''
- '''
if self.client_type == self.LINUX:
thread = threading.Thread(target= self.__start_skype_linux__)
thread.start()
@@ -150,22 +172,23 @@
thread = threading.Thread(target= self.__start_skype_windows__)
thread.start()
-
+ # --------------------------------------------------------------------------
+ # Stop Skype client.
+ # --------------------------------------------------------------------------
def stop(self):
+ '''Stop Skype client.
'''
- '''
if self.client_type == self.LINUX:
self.__stop_skype_linux__()
else:
self.__stop_skype_windows__()
-
-
+ # --------------------------------------------------------------------------
+ # Return true is skype client is installed, false otherwise.
+ # --------------------------------------------------------------------------
def isSkypeClientInstalled():
+ '''Return true is skype client is installed, false otherwise.
'''
- Return true is skype client is installed, false otherwise.
- '''
-
if os.name != 'nt':
#Checking path for skype.
for path in ( os.environ['PATH'].split(':') ):
@@ -179,17 +202,17 @@
res = os.listdir(os.environ['PROGRAMFILES'])
if ( 'skype' in res ) or ( 'Skype' in res ):
- return True
-
+ return True
return False
-
-
+ #Static method declaration.
isSkypeClientInstalled = staticmethod(isSkypeClientInstalled)
-
+# ==============================================================================
+# Declaration of the "ExtendedThread" object.
+# ==============================================================================
class ExtendedThread(Thread):
'''
Create an extended thread with stop method.
@@ -200,19 +223,22 @@
targetFunct = None
canRun = True
+ # --------------------------------------------------------------------------
+ # Initialize the thread.
+ # --------------------------------------------------------------------------
def __init__(self, target = None):
+ '''Initialize the thread.
'''
- Initialize the thread.
- '''
Thread.__init__(self)
self.targetFunct = target
canRun = True
-
+
+ # --------------------------------------------------------------------------
+ # Run the thread.
+ # --------------------------------------------------------------------------
def run(self):
+ '''Run the thread.
'''
- Runs the thread.
- '''
-
while self.canRun:
#Excetute attached function while stop is not call.
if ( self.targetFunct != None ):
@@ -221,21 +247,28 @@
else:
break
+ # --------------------------------------------------------------------------
+ # Stop the thread.
+ # --------------------------------------------------------------------------
def stop(self):
+ '''Stop the thread.
'''
- Stops the thread.
- '''
self.mutex.acquire()
self.targetFunct = None
self.canRun = False
self.mutex.release()
-
+# ==============================================================================
+# Declaration of the "AudioUtils" static class.
+# ==============================================================================
class AudioUtils(object):
'''
- Provide some windows utils functions.
+ Provide some audio util functions.
'''
+ # --------------------------------------------------------------------------
+ # Get a sound device by a keyword.
+ # --------------------------------------------------------------------------
def getSoundDeviceByKeywordWin32(deviceKeyword):
'''Get a sound device by a keyword.
@param deviceKeyword: Device keyword.
@@ -249,7 +282,9 @@
return i, deviceName
return -1, None
-
+ # --------------------------------------------------------------------------
+ # Get the sound device name of Tux Droid Audio.
+ # --------------------------------------------------------------------------
def getSoundDeviceNameTuxdroidAudio():
'''Get the sound device name of Tux Droid Audio.
@return: The device name or None (Win32) if not found.
@@ -260,7 +295,9 @@
else:
return "plughw:TuxDroid,0"
-
+ # --------------------------------------------------------------------------
+ # Get the sound device name of Tux Droid Micro.
+ # --------------------------------------------------------------------------
def getSoundDeviceNameTuxdroidMicro():
'''Get the sound device name of Tux Droid Micro.
@return: The device name or None (Win32) if not found.
@@ -282,32 +319,38 @@
else:
return "plughw:TuxDroid,0"
+
+ #Static methods declaration.
getSoundDeviceByKeywordWin32 = staticmethod(getSoundDeviceByKeywordWin32)
getSoundDeviceNameTuxdroidAudio = staticmethod(getSoundDeviceNameTuxdroidAudio)
getSoundDeviceNameTuxdroidMicro = staticmethod(getSoundDeviceNameTuxdroidMicro)
-
+
+# ==============================================================================
+# Declaration of the "StringUtils" static class.
+# ==============================================================================
class StringUtils(object):
+ '''Offers string utilities.
'''
- Offers string utilities.
- '''
+ # --------------------------------------------------------------------------
+ # Return a string removing all 'not tts pretty' characters.
+ # --------------------------------------------------------------------------
def toPrettyString(myString):
+ '''Return a string removing all 'not tts pretty' characters.
'''
- Return a string removing all 'not tts pretty' characters.
- '''
pattern = ['[', '^', '"', ']', '+', ')', '"', '>', '(', '[', '^', '>', ']', '+', '.',
')', '<', '/', '>', '-', '_', '{', '}', '@', '!', '*', '=', ':', ';', ',', "'"]
for rep in pattern:
myString = myString.replace(rep, ' ')
return myString
-
-
+ # --------------------------------------------------------------------------
+ # Cut a phone number to a pretty tts phone number.
+ # --------------------------------------------------------------------------
def phoneNumberToTTS(myPhoneNumber):
+ '''Cut a phone number to a pretty tts phone number.
'''
- Cut a phone number to a pretty tts phone number.
- '''
print myPhoneNumber
finalString = '+'
#Removing '+' from the string.
@@ -321,8 +364,7 @@
while pos != ( x - 1 ):
finalString += ' ' + myPhoneNumber[pos] + myPhoneNumber[pos + 1]
pos += 2
- finalString += ' ' + myPhoneNumber[pos] + myPhoneNumber[pos + 1]
-
+ finalString += ' ' + myPhoneNumber[pos] + myPhoneNumber[pos + 1]
else:
#then impair number.
pos = 0
@@ -333,24 +375,27 @@
pos += 2
finalString += ' ' + myPhoneNumber[pos] + myPhoneNumber[pos + 1] + myPhoneNumber[pos +2]
- print finalString
return finalString
-
+ #Static methods declaration.
toPrettyString = staticmethod(toPrettyString)
phoneNumberToTTS = staticmethod(phoneNumberToTTS)
-
+
+# ==============================================================================
+# Declaration of the "TuxDroidServerUtils" static class.
+# ==============================================================================
class TuxDroidServerUtils(object):
- '''
- Provide Tux Droid server utils functions.
+ '''Provide Tux Droid server utils functions.
'''
+ #--------------------------------------------------------------------------
+ # Return the current server port.
+ # --------------------------------------------------------------------------
def getServerPort():
+ '''Return the current server port.
'''
- Return the current server port.
- '''
if os.name == "nt":
return 270
else:
@@ -359,11 +404,12 @@
else:
return 54321
-
+ #--------------------------------------------------------------------------
+ # Send a request to tuxhttpserver.
+ # --------------------------------------------------------------------------
def sendRequest(host, port, request):
+ '''Send a request to tuxhttpserver.
'''
- Send a request to tuxhttpserver.
- '''
import socket
import httplib
@@ -386,6 +432,6 @@
socket.setdefaulttimeout(old_timeout)
return 0
-
+ #Static methods declaration.
getServerPort = staticmethod(getServerPort)
sendRequest = staticmethod(sendRequest)
|