1 from Components.Sources.Source import Source
2 from Screens.MessageBox import MessageBox
3 from os import system, path
8 yesnoFile = "/tmp/yesno"
10 def __init__(self, session, func=PRINT):
12 self.session = session
16 error = "unknown command (%s)" % func
17 self.res = (False, error)
19 def handleCommand(self, cmd):
21 if self.func is self.PRINT:
22 self.res = self.printMessage(cmd)
23 elif self.func is self.ANSWER:
24 self.res = self.getYesNoAnswer(cmd)
26 def printMessage(self, param):
29 if self.cmd['text'] == "" or self.cmd['text'] is None:
30 return ( False, "No Messagetext given" )
32 mtext = self.cmd['text']
35 typeint = int(self.cmd['type'])
37 return ( False, "type %s is not a number" % self.cmd['type'] )
39 if typeint == MessageBox.TYPE_YESNO:
40 #dont know how to give the result to the webif back
41 mtype = MessageBox.TYPE_YESNO
42 elif typeint == MessageBox.TYPE_INFO:
43 mtype = MessageBox.TYPE_INFO
44 elif typeint == MessageBox.TYPE_WARNING:
45 mtype = MessageBox.TYPE_WARNING
46 elif typeint == MessageBox.TYPE_ERROR:
47 mtype = MessageBox.TYPE_ERROR
49 return ( False, "Unsupported Messagetype %s" % self.cmd['type'] )
52 mtimeout = int(self.cmd['timeout'])
56 if typeint == MessageBox.TYPE_YESNO:
57 self.session.openWithCallback(self.yesNoAnswer, MessageBox, mtext, type=mtype, timeout=mtimeout)
59 self.session.open(MessageBox, mtext, type=mtype , timeout=mtimeout)
61 return ( True, "Message sent successfully!" )
63 def yesNoAnswer(self, confirmed):
64 print "yesNoAnswer", confirmed
65 #self.session.messageboxanswer = confirmed
67 yesnoFile = self.yesnoFile
69 cmdstr = "/bin/echo -n yes > %s" % yesnoFile
71 cmdstr = "/bin/echo -n no > %s" % yesnoFile
75 def getYesNoAnswer(self, param):
76 print "getYesNoAnswer"#,self.session.messageboxanswer
77 yesnoFile = self.yesnoFile
78 if path.exists(yesnoFile) == True:
79 file = open(yesnoFile, "r")
80 lines = file.readlines()
82 cmdstr = "rm %s" % yesnoFile
84 print "Answer: (%s)" % lines[0]
86 return ( True, "Answer is YES!" )
88 return ( True, "Answer is NO!" )
90 return ( False, "No answer in time" )
92 result = property(lambda self: self.res)