15 _moduleLogger = logging.getLogger("channel.debug_prompt")
18 class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
20 def __init__(self, connection, manager, props, contactHandle):
21 self.__manager = manager
24 cmd.Cmd.__init__(self, "Debug Prompt")
25 self.use_rawinput = False
26 tp.ChannelTypeText.__init__(self, connection, manager, props)
27 self.__nextRecievedId = 0
28 self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
30 self.__otherHandle = contactHandle
32 @gtk_toolbox.log_exception(_moduleLogger)
33 def Send(self, messageType, text):
34 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
35 raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
37 self.Sent(int(time.time()), messageType, text)
39 oldStdin, oldStdout = self.stdin, self.stdout
41 self.stdin = currentStdin = StringIO.StringIO()
42 self.stdout = currentStdout = StringIO.StringIO()
45 self.stdin, self.stdout = oldStdin, oldStdout
47 stdoutData = currentStdout.getvalue().strip()
49 self._report_new_message(stdoutData)
51 @gtk_toolbox.log_exception(_moduleLogger)
56 _moduleLogger.debug("Closing debug")
57 tp.ChannelTypeText.Close(self)
58 self.remove_from_connection()
60 def _report_new_message(self, message):
61 currentReceivedId = self.__nextRecievedId
63 timestamp = int(time.time())
64 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
66 self.Received(currentReceivedId, timestamp, self.__otherHandle, type, 0, message.strip())
68 self.__nextRecievedId += 1
70 def do_reset_state_machine(self, args):
72 self._report_new_message("No arguments supported")
76 for machine in self._conn.session.stateMachine._machines:
77 machine.reset_timers()
79 self._report_new_message(str(e))
81 def help_reset_state_machine(self):
82 self._report_new_message("Reset the refreshing state machine")
84 def do_get_state(self, args):
86 self._report_new_message("No arguments supported")
90 state = self._conn.session.stateMachine.state
91 self._report_new_message(str(state))
93 self._report_new_message(str(e))
95 def help_get_state(self):
96 self._report_new_message("Print the current state the refreshing state machine is in")
98 def do_is_authed(self, args):
100 self._report_new_message("No arguments supported")
104 isAuthed = self._conn.session.backend.is_authed()
105 self._report_new_message(str(isAuthed))
107 self._report_new_message(str(e))
109 def help_is_authed(self):
110 self._report_new_message("Print whether logged in to Google Voice")
112 def do_is_dnd(self, args):
114 self._report_new_message("No arguments supported")
118 isDnd = self._conn.session.backend.is_dnd()
119 self._report_new_message(str(isDnd))
121 self._report_new_message(str(e))
123 def help_is_dnd(self):
124 self._report_new_message("Print whether Do-Not-Disturb mode enabled on the Google Voice account")
126 def do_get_account_number(self, args):
128 self._report_new_message("No arguments supported")
132 number = self._conn.session.backend.get_account_number()
133 self._report_new_message(number)
135 self._report_new_message(str(e))
137 def help_get_account_number(self):
138 self._report_new_message("Print the Google Voice account number")
140 def do_get_callback_numbers(self, args):
142 self._report_new_message("No arguments supported")
146 numbers = self._conn.session.backend.get_callback_numbers()
147 numbersDisplay = "\n".join(
148 "%s: %s" % (name, number)
149 for (number, name) in numbers.iteritems()
151 self._report_new_message(numbersDisplay)
153 self._report_new_message(str(e))
155 def help_get_callback_numbers(self):
156 self._report_new_message("Print a list of all configured callback numbers")
158 def do_get_sane_callback_number(self, args):
160 self._report_new_message("No arguments supported")
164 number = gvoice.backend.get_sane_callback(self._conn.session.backend)
165 self._report_new_message(number)
167 self._report_new_message(str(e))
169 def help_get_sane_callback_number(self):
170 self._report_new_message("Print the best guess of callback numbers to use")
172 def do_get_callback_number(self, args):
174 self._report_new_message("No arguments supported")
178 number = self._conn.session.backend.get_callback_number()
179 self._report_new_message(number)
181 self._report_new_message(str(e))
183 def help_get_callback_number(self):
184 self._report_new_message("Print the callback number currently enabled")
186 def do_call(self, args):
188 self._report_new_message("Must specify the phone number and only the phone nunber")
193 self._conn.session.backend.call(number)
195 self._report_new_message(str(e))
198 self._report_new_message("\n".join(["call NUMBER", "Initiate a callback, Google forwarding the call to the callback number"]))
200 def do_send_sms(self, args):
202 self._report_new_message("Must specify the phone number and then message")
207 message = " ".join(args[1:])
208 self._conn.session.backend.send_sms(number, message)
210 self._report_new_message(str(e))
212 def help_send_sms(self):
213 self._report_new_message("\n".join(["send_sms NUMBER MESSAGE0 MESSAGE1 ...", "Send an sms to number NUMBER"]))
215 def do_version(self, args):
217 self._report_new_message("No arguments supported")
219 self._report_new_message("%s-%s" % (constants.__version__, constants.__build__))
221 def help_version(self):
222 self._report_new_message("Prints the version (hint: %s-%s)" % (constants.__version__, constants.__build__))
224 def do_get_polling(self, args):
226 self._report_new_message("No arguments supported")
228 self._report_new_message("\n".join((
229 "Contacts:", repr(self._conn.session.addressbookStateMachine)
231 self._report_new_message("\n".join((
232 "Voicemail:", repr(self._conn.session.voicemailsStateMachine)
234 self._report_new_message("\n".join((
235 "Texts:", repr(self._conn.session.textsStateMachine)
238 def help_get_polling(self):
239 self._report_new_message("Prints the frequency each of the state machines updates")
241 def do_grab_log(self, args):
243 self._report_new_message("No arguments supported")
245 publishProps = self._conn._generate_props(telepathy.CHANNEL_TYPE_FILE_TRANSFER, self.__otherHandle, False)
246 self._conn._channel_manager.channel_for_props(publishProps, signal=True)
248 def help_grab_log(self):
249 self._report_new_message("Download the debug log for including with bug report")
250 self._report_new_message("Warning: this may contain sensitive information")