[tuxdroid-svn] r1410 - in software_suite_v2/software: . chatterTuxServer chatterTuxServer/trunk cha
Status: Beta
Brought to you by:
ks156
From: remi <c2m...@c2...> - 2008-07-29 08:01:00
|
Author: remi Date: 2008-07-29 10:01:09 +0200 (Tue, 29 Jul 2008) New Revision: 1410 Added: software_suite_v2/software/chatterTuxServer/ software_suite_v2/software/chatterTuxServer/branches/ software_suite_v2/software/chatterTuxServer/tags/ software_suite_v2/software/chatterTuxServer/trunk/ software_suite_v2/software/chatterTuxServer/trunk/chattertux_start.bat software_suite_v2/software/chatterTuxServer/trunk/chattertux_stop.bat software_suite_v2/software/chatterTuxServer/trunk/chattertuxsender.bat software_suite_v2/software/chatterTuxServer/trunk/chattertuxsenderx.bat software_suite_v2/software/chatterTuxServer/trunk/chtuxstart.ico software_suite_v2/software/chatterTuxServer/trunk/chtuxstop.ico software_suite_v2/software/chatterTuxServer/trunk/files/ software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.ini software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.py software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxHTTPServer.py software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxSender.py software_suite_v2/software/chatterTuxServer/trunk/files/ConfIni.py software_suite_v2/software/chatterTuxServer/trunk/installer.nsi Log: * added "chatterTuxServer" project Added: software_suite_v2/software/chatterTuxServer/trunk/chattertux_start.bat =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/chattertux_start.bat (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/chattertux_start.bat 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1 @@ +c:/tuxdroid/bin/python/python.exe c:/tuxdroid/bin/chattertux/ChatterTux.py \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/chattertux_stop.bat =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/chattertux_stop.bat (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/chattertux_stop.bat 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1 @@ +c:/tuxdroid/bin/chattertuxsender CMD:SERVER:CLOSE \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/chattertuxsender.bat =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/chattertuxsender.bat (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/chattertuxsender.bat 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1 @@ +c:/tuxdroid/bin/python/python.exe c:/tuxdroid/bin/chattertux/ChatterTuxSender.py 127.0.0.1 271 %1 \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/chattertuxsenderx.bat =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/chattertuxsenderx.bat (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/chattertuxsenderx.bat 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1 @@ +c:/tuxdroid/bin/python/python.exe c:/tuxdroid/bin/chattertux/ChatterTuxSender.py %1 %2 %3 \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/chtuxstart.ico =================================================================== (Binary files differ) Property changes on: software_suite_v2/software/chatterTuxServer/trunk/chtuxstart.ico ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software_suite_v2/software/chatterTuxServer/trunk/chtuxstop.ico =================================================================== (Binary files differ) Property changes on: software_suite_v2/software/chatterTuxServer/trunk/chtuxstop.ico ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.ini =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.ini (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.ini 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1,59 @@ +[VOICE CONFIGURATION] +locutor = Bruno +pitch = 130 + +[:)] +action = tts +cmd = Je suis content ! + +[:(] +action = tts +cmd = Merde ! + +[oeil] +action = api +cmd = tux.eyes.onAsync(2, SSV_NDEF) + +[bouche] +action = api +cmd = tux.mouth.onAsync(2, SSV_NDEF) + +[ailes] +action = api +cmd = tux.flippers.onAsync(2, SSV_NDEF) + +[tux] +action = tts +cmd = Teucksss ! C'est moi ! + +[lol] +action = tts +cmd = Ha ha ha + +[mdr] +action = tts +cmd = Mort de rire ! + +[non] +action = tts +cmd = Non non ! + +[salut] +action = tts +cmd = Salut mec ! + +[bye] +action = tts +cmd = Bye ! + +[R] +action = tts +cmd = Je vais le dire a R ! + +[je] +action = api +cmd = tux.eyes.onAsync(2, SSV_NDEF) + +[le] +action = api +cmd = tux.mouth.onAsync(2, SSV_NDEF) \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.py =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.py (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTux.py 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1,79 @@ +import time +import sys +import signal +import os +import threading + +from tuxisalive.api import * +from ChatterTuxHTTPServer import ChatterTuxHTTPServer, handler +from tuxisalive.lib.wordlogger import WordLogger +from ConfIni import readConf + +APPLICATION_PATH = os.path.realpath(os.path.dirname(sys.argv[0])) +myConf = readConf(os.path.join(APPLICATION_PATH, "ChatterTux.ini")) + +tux = TuxAPI('127.0.0.1', 270) +tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'ChatterTux', 'nopasswd') + +if myConf.has_key("VOICE CONFIGURATION"): + tux.tts.setLocutor(myConf["VOICE CONFIGURATION"]["locutor"]) + tux.tts.setPitch(eval(myConf["VOICE CONFIGURATION"]["pitch"])) + +def onCmdServerClose(*args): + twl.stop() + tux.destroy() + s.stop() + +def playAttitune(path): + if tux.access.acquire(): + if tux.attitune.load(path): + tux.attitune.play() + tux.access.release() + +def _onEventWord(word): + try: + tux.attitune.stop() + tux.tts.stop() + tux.wav.stop() + action = myConf[word] + if action["action"] == "tts": + if tux.access.acquire(): + tux.tts.speakAsync(action["cmd"]) + tux.access.release() + elif action["action"] == "attitune": + playAttitune(action["cmd"]) + elif action["action"] == "api": + if action["cmd"].find("tux.") == 0: + try: + if tux.access.acquire(): + exec(action["cmd"]) in globals() + tux.access.release() + except: + pass + elif action["action"] == "wav": + if tux.access.acquire(): + tux.wav.play(action["cmd"]) + tux.access.release() + except: + pass + +def onEventWord(p1, p2, word): + word = word.upper() + print word + if myConf.has_key(word): + t = threading.Thread(target = _onEventWord, args = (word,)) + t.start() + +def onEventWord2(word): + onEventWord("", "", word) + +if __name__ == "__main__": + handler.register(onEventWord, ("EVENT", "WORD", None)) + handler.register(onCmdServerClose, ("CMD", "SERVER", "CLOSE")) + s = ChatterTuxHTTPServer() + t = threading.Thread(target = s.start) + t.start() + + twl = WordLogger() + twl.handler.register(onEventWord2) + twl.start() Added: software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxHTTPServer.py =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxHTTPServer.py (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxHTTPServer.py 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1,173 @@ +# -*- coding: latin1 -*- + + +# Copyright (C) 2008 C2ME Sa +# R Jocaille <rem...@c2...> +# Distributed under the terms of the GNU General Public License +# http://www.gnu.org/copyleft/gpl.html + +from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer +from SocketServer import ThreadingMixIn +import threading +import re +import urllib +import sys +import httplib +import time + +from tuxisalive.lib.logger import * +from tuxisalive.api.TuxEventHandler import TuxEventHandler + +handler = TuxEventHandler() + +class ChatterTuxHTTPServer(object): + """ + """ + + def __init__(self, port = 271): + """ + """ + self.__logger = SimpleLogger("ChatterTuxServer") + self.__logger.resetLog() + self.__logger.setLevel(LOG_LEVEL_DEBUG) + self.__logger.setTarget(LOG_TARGET_BOTH) + self.__port = port + self.__started = False + self.__startedMutex = threading.Lock() + self.__server = None + self.__quit = False + self.__createServer() + + def __createServer(self): + """ + """ + if self.__server != None: + return False + + self.__killOldServer() + + try: + self.__server = HTTPServer(('', self.__port), TDHttpRequestHandler) + self.__logger.logInfo("Create a server on port %d" % self.__port) + except: + self.__server = None + return False + + return True + + def __killOldServer(self): + """ + """ + h = httplib.HTTP("127.0.0.1:%s", self.__port) + try: + h.connect() + except: + return + h.putrequest("GET", "CMD:SERVER:CLOSE") + h.endheaders() + try: + errcode, errmsg, headers = h.getreply() + time.sleep(1.0) + except: + pass + + def start(self): + """ + """ + if self.__getStarted(): + return False + + if self.__server == None: + return False + + try: + self.__setStarted(True) + self.__logger.logInfo("Server started.") + self.__serve_forever() + except: + pass + + self.__logger.logInfo("Server stopped.") + return True + + def __serve_forever(self): + self.__quit = False + while not self.__quit: + self.__server.handle_request() + self.__server.server_close() + + def stop(self): + """ + """ + self.__quit = True + + def __setStarted(self, value = True): + """ + """ + self.__startedMutex.acquire() + self.__started = value + self.__startedMutex.release() + + def __getStarted(self): + """ + """ + value = False + self.__startedMutex.acquire() + value = self.__started + self.__startedMutex.release() + return value + +class TDHttpRequestHandler(BaseHTTPRequestHandler): + """ + """ + + def do_GET(self): + """ + """ + try: + self.path = urllib.unquote_plus(self.path) + + p = self.path.split(":") + if len(p) == 3: + handler.emit(*tuple(p)) + elif len(p) > 3: + np = [] + lastArg = "" + for i, a in enumerate(p): + if i >= 2: + if i == 2: + lastArg = a + else: + lastArg = "%s:%s" % (lastArg, a) + else: + np.append(a) + np.append(lastArg) + handler.emit(*tuple(np)) + + except: + self.send_response(404) + try: + self.send_response(200) + except: + print "Handle error" + + def handle_one_request(self): + """ + """ + try: + BaseHTTPRequestHandler.handle_one_request(self) + except: + print "handle_one_request error" + + def log_request(self, code='-', size='-'): + """ + """ + pass + +if __name__ == "__main__": + def onRequest(cmdType, cmd, value): + print cmdType, cmd, value + + handler.register(onRequest, ("EVENT", "WORD", None)) + s = ChatterTuxHTTPServer() + s.start() \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxSender.py =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxSender.py (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/files/ChatterTuxSender.py 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1,29 @@ +import httplib +import sys + +def sendRequest(host, port, request): + hp = "%s:%d" % (host, port) + h = httplib.HTTP(hp) + try: + h.connect() + except: + return 1 + h.putrequest("GET", request) + h.endheaders() + errcode, errmsg, headers = h.getreply() + if errcode != 200: + return 1 + else: + return 0 + +if __name__ == "__main__": + if len(sys.argv) != 4: + sys.exit(1) + host = sys.argv[1] + try: + port = eval(sys.argv[2]) + except: + sys.exit(1) + request = sys.argv[3] + ret = sendRequest(host, port, request) + sys.exit(ret) \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/files/ConfIni.py =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/files/ConfIni.py (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/files/ConfIni.py 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1,35 @@ +import sys +import re +import os + +SECTION = re.compile('^\s*\[\s*([^\]]*)\s*\]\s*$') +PARAM = re.compile('^\s*(\w+)\s*=\s*(.*)\s*$') +COMMENT = re.compile('^\s*;.*$') + +def readConf(iniPath): + """ + """ + result = {} + + if not os.path.isfile(iniPath): + return result + try: + f = open(iniPath) + except: + return result + d = {} + for line in f: + if COMMENT.match(line): continue + m = SECTION.match(line) + if m: + section, = m.groups() + d[section] = {} + m = PARAM.match(line) + if m: + key, val = m.groups() + d[section][key] = val + + for k, v in d.items(): + result[k.upper()] = v + + return result \ No newline at end of file Added: software_suite_v2/software/chatterTuxServer/trunk/installer.nsi =================================================================== --- software_suite_v2/software/chatterTuxServer/trunk/installer.nsi (rev 0) +++ software_suite_v2/software/chatterTuxServer/trunk/installer.nsi 2008-07-29 08:01:09 UTC (rev 1410) @@ -0,0 +1,99 @@ +; installer.nsi +; This installer which install the python 2.4 for tuxdroid use +; ----------------------------------------------------------------------------- + +; HM NIS Edit Wizard helper defines +!define PRODUCT_NAME "Chatter Tux" +!define PRODUCT_VERSION "0.0.1-ALPHA" + + +; The name of the installer +Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" + +; The file to write +OutFile "chatterTux_${PRODUCT_VERSION}.exe" + +; The default installation directory +InstallDir c:\tuxdroid\bin\chattertux + +; Request application privileges for Windows Vista +RequestExecutionLevel user + +; ----------------------------------------------------------------------------- +; Section "" +; ----------------------------------------------------------------------------- + +Section "" + ; Check that the tuxisalive package + ReadRegStr $0 HKLM SOFTWARE\Tuxdroid\pyTuxisalive "Install_Dir" + StrCmp $0 "" endNoInstall + + ; Write the file in c:\tuxdroid\bin\python + SetOutPath $INSTDIR + SetOverwrite ifnewer + File /r files\* + + SetOutPath "c:\tuxdroid\bin" + SetOverwrite ifnewer + File "chattertux_start.bat" + File "chattertux_stop.bat" + File "chattertuxsender.bat" + File "chattertuxsenderx.bat" + + SetOutPath "c:\tuxdroid\ico" + SetOverwrite ifnewer + File "chtuxstart.ico" + File "chtuxstop.ico" + + ; Write shortcut in start menu + CreateDirectory "$SMPROGRAMS\Tuxdroid" + CreateDirectory "$SMPROGRAMS\Tuxdroid\ChatterTux" + CreateShortCut "$SMPROGRAMS\Tuxdroid\ChatterTux\Start.lnk" "c:\tuxdroid\bin\chattertux_start.bat" "" "c:\tuxdroid\ico\chtuxstart.ico" 0 + CreateShortCut "$SMPROGRAMS\Tuxdroid\ChatterTux\Stop.lnk" "c:\tuxdroid\bin\chattertux_stop.bat" "" "c:\tuxdroid\ico\chtuxstop.ico" 0 + + ; Write the installation path into the registry + WriteRegStr HKLM SOFTWARE\Tuxdroid\chatterTux "Install_Dir" "$INSTDIR" + + ; Write the uninstall keys for Windows + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\chatterTux" "DisplayName" "${PRODUCT_NAME} ${PRODUCT_VERSION}" + WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\chatterTux" "UninstallString" "$INSTDIR\uninstall.exe" + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\chatterTux" "NoModify" 1 + WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\chatterTux" "NoRepair" 1 + + ; Write the uninstall file + WriteUninstaller "uninstall.exe" + Quit + + endNoInstall: + MessageBox MB_OK "Aborded : Tuxisalive python package not found." + Quit +SectionEnd + +; ----------------------------------------------------------------------------- +; Section "Uninstall" +; ----------------------------------------------------------------------------- + +Section "Uninstall" + ExecWait "c:\tuxdroid\bin\chattertux_stop.bat" + + ; Remove registry keys + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\chatterTux" + DeleteRegKey HKLM SOFTWARE\Tuxdroid\chatterTux + + ; Remove files and uninstaller + RMDir /r $INSTDIR + Delete $INSTDIR\uninstall.exe + Delete "c:\tuxdroid\bin\chattertux_start.bat" + Delete "c:\tuxdroid\bin\chattertux_stop.bat" + Delete "c:\tuxdroid\bin\chattertuxsender.bat" + Delete "c:\tuxdroid\bin\chattertuxsenderx.bat" + Delete "c:\tuxdroid\ico\chtuxstart.ico" + Delete "c:\tuxdroid\ico\chtuxstop.ico" + + ; Remove shortcuts + Delete "$SMPROGRAMS\Tuxdroid\ChatterTux\*.*" + RMDir "$SMPROGRAMS\Tuxdroid\ChatterTux" + + ; Quit the uninstaller + Quit +SectionEnd |