14 _moduleLogger = logging.getLogger("channel.text")
17 class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
19 @todo Look into implementing ChannelInterfaceMessages for rich text formatting
20 @todo Add a command that initiates a file transfer, giving the log file to the user
23 def __init__(self, connection, manager, props, contactHandle):
24 self.__manager = manager
27 cmd.Cmd.__init__(self, "Debug Prompt")
28 self.use_rawinput = False
29 tp.ChannelTypeText.__init__(self, connection, manager, props)
30 self.__nextRecievedId = 0
31 self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
33 self.__otherHandle = contactHandle
35 @gtk_toolbox.log_exception(_moduleLogger)
36 def Send(self, messageType, text):
37 if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
38 raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
40 self.Sent(int(time.time()), messageType, text)
42 oldStdin, oldStdout = self.stdin, self.stdout
44 self.stdin = currentStdin = StringIO.StringIO()
45 self.stdout = currentStdout = StringIO.StringIO()
48 self.stdin, self.stdout = oldStdin, oldStdout
50 self._report_new_message(currentStdout.getvalue())
52 @gtk_toolbox.log_exception(_moduleLogger)
57 _moduleLogger.debug("Closing debug")
58 tp.ChannelTypeText.Close(self)
59 self.remove_from_connection()
61 def _report_new_message(self, message):
62 currentReceivedId = self.__nextRecievedId
64 timestamp = int(time.time())
65 type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
67 self.Received(currentReceivedId, timestamp, self.__otherHandle, type, 0, message.strip())
69 self.__nextRecievedId += 1
71 def do_reset_state_machine(self, args):
73 self._report_new_message("No arguments supported")
77 for machine in self._conn.session.stateMachine._machines:
78 machine.reset_timers()
80 self._report_new_message(str(e))
82 def help_reset_state_machine(self):
83 self._report_new_message("Reset the refreshing state machine")
85 def do_get_state(self, args):
87 self._report_new_message("No arguments supported")
91 state = self._conn.session.stateMachine.state
92 self._report_new_message(str(state))
94 self._report_new_message(str(e))
96 def help_get_state(self):
97 self._report_new_message("Print the current state the refreshing state machine is in")
99 def do_is_authed(self, args):
101 self._report_new_message("No arguments supported")
105 isAuthed = self._conn.session.backend.is_authed()
106 self._report_new_message(str(isAuthed))
108 self._report_new_message(str(e))
110 def help_is_authed(self):
111 self._report_new_message("Print whether logged in to Google Voice")
113 def do_is_dnd(self, args):
115 self._report_new_message("No arguments supported")
119 isDnd = self._conn.session.backend.is_dnd()
120 self._report_new_message(str(isDnd))
122 self._report_new_message(str(e))
124 def help_is_dnd(self):
125 self._report_new_message("Print whether Do-Not-Disturb mode enabled on the Google Voice account")
127 def do_get_account_number(self, args):
129 self._report_new_message("No arguments supported")
133 number = self._conn.session.backend.get_account_number()
134 self._report_new_message(number)
136 self._report_new_message(str(e))
138 def help_get_account_number(self):
139 self._report_new_message("Print the Google Voice account number")
141 def do_get_callback_numbers(self, args):
143 self._report_new_message("No arguments supported")
147 numbers = self._conn.session.backend.get_callback_numbers()
148 numbersDisplay = "\n".join(
149 "%s: %s" % (name, number)
150 for (number, name) in numbers.iteritems()
152 self._report_new_message(numbersDisplay)
154 self._report_new_message(str(e))
156 def help_get_callback_numbers(self):
157 self._report_new_message("Print a list of all configured callback numbers")
159 def do_get_sane_callback_number(self, args):
161 self._report_new_message("No arguments supported")
165 number = gvoice.backend.get_sane_callback(self._conn.session.backend)
166 self._report_new_message(number)
168 self._report_new_message(str(e))
170 def help_get_sane_callback_number(self):
171 self._report_new_message("Print the best guess of callback numbers to use")
173 def do_get_callback_number(self, args):
175 self._report_new_message("No arguments supported")
179 number = self._conn.session.backend.get_callback_number()
180 self._report_new_message(number)
182 self._report_new_message(str(e))
184 def help_get_callback_number(self):
185 self._report_new_message("Print the callback number currently enabled")
187 def do_call(self, args):
189 self._report_new_message("Must specify the phone number and only the phone nunber")
194 self._conn.session.backend.call(number)
196 self._report_new_message(str(e))
199 self._report_new_message("\n".join(["call NUMBER", "Initiate a callback, Google forwarding the call to the callback number"]))
201 def do_send_sms(self, args):
203 self._report_new_message("Must specify the phone number and then message")
208 message = " ".join(args[1:])
209 self._conn.session.backend.send_sms(number, message)
211 self._report_new_message(str(e))
213 def help_send_sms(self):
214 self._report_new_message("\n".join(["send_sms NUMBER MESSAGE0 MESSAGE1 ...", "Send an sms to number NUMBER"]))