14 _moduleLogger = logging.getLogger("channel.text")
17 class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
19 def __init__(self, connection, manager, props, contactHandle):
20 self.__manager = manager
23 cmd.Cmd.__init__(self, "Debug Prompt")
24 self.use_rawinput = False
25 tp.ChannelTypeText.__init__(self, connection, manager, props)
26 self.__nextRecievedId = 0
27 self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
29 self.__otherHandle = contactHandle
31 @gtk_toolbox.log_exception(_moduleLogger)
32 def Send(self, messageType, text):
33 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
34 raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
36 self.Sent(int(time.time()), messageType, text)
38 oldStdin, oldStdout = self.stdin, self.stdout
40 self.stdin = currentStdin = StringIO.StringIO()
41 self.stdout = currentStdout = StringIO.StringIO()
44 self.stdin, self.stdout = oldStdin, oldStdout
46 self._report_new_message(currentStdout.getvalue())
48 @gtk_toolbox.log_exception(_moduleLogger)
53 _moduleLogger.debug("Closing debug")
54 tp.ChannelTypeText.Close(self)
55 self.remove_from_connection()
57 def _report_new_message(self, message):
58 currentReceivedId = self.__nextRecievedId
60 timestamp = int(time.time())
61 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
63 self.Received(currentReceivedId, timestamp, self.__otherHandle, type, 0, message.strip())
65 self.__nextRecievedId += 1
67 def do_reset_state_machine(self, args):
69 self._report_new_message("No arguments supported")
73 for machine in self._conn.session.stateMachine._machines:
74 machine.reset_timers()
76 self._report_new_message(str(e))
78 def help_reset_state_machine(self):
79 self._report_new_message("Reset the refreshing state machine")
81 def do_get_state(self, args):
83 self._report_new_message("No arguments supported")
87 state = self._conn.session.stateMachine.state
88 self._report_new_message(str(state))
90 self._report_new_message(str(e))
92 def help_get_state(self):
93 self._report_new_message("Print the current state the refreshing state machine is in")
95 def do_is_authed(self, args):
97 self._report_new_message("No arguments supported")
101 isAuthed = self._conn.session.backend.is_authed()
102 self._report_new_message(str(isAuthed))
104 self._report_new_message(str(e))
106 def help_is_authed(self):
107 self._report_new_message("Print whether logged in to Google Voice")
109 def do_is_dnd(self, args):
111 self._report_new_message("No arguments supported")
115 isDnd = self._conn.session.backend.is_dnd()
116 self._report_new_message(str(isDnd))
118 self._report_new_message(str(e))
120 def help_is_dnd(self):
121 self._report_new_message("Print whether Do-Not-Disturb mode enabled on the Google Voice account")
123 def do_get_account_number(self, args):
125 self._report_new_message("No arguments supported")
129 number = self._conn.session.backend.get_account_number()
130 self._report_new_message(number)
132 self._report_new_message(str(e))
134 def help_get_account_number(self):
135 self._report_new_message("Print the Google Voice account number")
137 def do_get_callback_numbers(self, args):
139 self._report_new_message("No arguments supported")
143 numbers = self._conn.session.backend.get_callback_numbers()
144 numbersDisplay = "\n".join(
145 "%s: %s" % (name, number)
146 for (number, name) in numbers.iteritems()
148 self._report_new_message(numbersDisplay)
150 self._report_new_message(str(e))
152 def help_get_callback_numbers(self):
153 self._report_new_message("Print a list of all configured callback numbers")
155 def do_get_sane_callback_number(self, args):
157 self._report_new_message("No arguments supported")
161 number = gvoice.backend.get_sane_callback(self._conn.session.backend)
162 self._report_new_message(number)
164 self._report_new_message(str(e))
166 def help_get_sane_callback_number(self):
167 self._report_new_message("Print the best guess of callback numbers to use")
169 def do_get_callback_number(self, args):
171 self._report_new_message("No arguments supported")
175 number = self._conn.session.backend.get_callback_number()
176 self._report_new_message(number)
178 self._report_new_message(str(e))
180 def help_get_callback_number(self):
181 self._report_new_message("Print the callback number currently enabled")
183 def do_call(self, args):
185 self._report_new_message("Must specify the phone number and only the phone nunber")
190 self._conn.session.backend.call(number)
192 self._report_new_message(str(e))
195 self._report_new_message("\n".join(["call NUMBER", "Initiate a callback, Google forwarding the call to the callback number"]))
197 def do_send_sms(self, args):
199 self._report_new_message("Must specify the phone number and then message")
204 message = " ".join(args[1:])
205 self._conn.session.backend.send_sms(number, message)
207 self._report_new_message(str(e))
209 def help_send_sms(self):
210 self._report_new_message("\n".join(["send_sms NUMBER MESSAGE0 MESSAGE1 ...", "Send an sms to number NUMBER"]))