rendered paste bodyimport os
import sys
import subprocess
import re
import pexpect
bolQuiet = 0
def doCmd(strName, strCmd, strArg):
global bolQuiet
strReturn = ""
if strName=="^1WireDDD^7^^018^2SA" and strCmd == "toggle":
if strArg == "quiet":
if bolQuiet == 1:
bolQuiet = 0
else:
bolQuiet = 1
else:
strReturn = "say your name is " + strName + ", your command was " + strCmd + ", your argument was " + strArg + "\n"
return strReturn
def parsecommand(strLine):
strReturn = ""
strName = ""
strArg = ""
strCmd = ""
strStriped = strLine.replace("^0","^7")
strStriped = strStriped.replace("^1","^7")
strStriped = strStriped.replace("^2","^7")
strStriped = strStriped.replace("^3","^7")
strStriped = strStriped.replace("^4","^7")
strStriped = strStriped.replace("^5","^7")
strStriped = strStriped.replace("^6","^7")
strStriped = strStriped.replace("^8","^7")
strStriped = strStriped.replace("^9","^7")
strStriped = strStriped.replace("^0","^7")
arrStripedCmd = strStriped.split(" ^7$")
if len(arrStripedCmd) > 1:
arrCmdSplit = arrStripedCmd[1].split()
arrName = strLine.split("^7: ^2$")
if len(arrName) > 1:
strName = arrName[0]
if len(arrCmdSplit) > 0:
strCmd = arrCmdSplit[0]
if len(arrCmdSplit) > 1:
strArg = arrCmdSplit[1]
strCmd = strCmd.replace("^","")
strArg = strArg.replace("^","")
if len(strCmd) == 0:
strReturn = None
else:
strReturn = doCmd(strName, strCmd, strArg)
return strReturn
def parsettyline(strLine):
if re.compile(".+:.\^[0-9]\$.+").match(strLine, 1):
return parsecommand(strLine)
s = pexpect.spawn ('/home/wired/tremulous/tremulous.x86', timeout = None)
while s.eof() == False:
mess = s.readline()
print mess
strResponse = parsettyline(mess)
if strResponse != None:
print strResponse
if bolQuiet == 0:
s.write(strResponse)
s.close()
sys.exit(0)