Playing with watching various dbus signals
[theonering] / src / channel / debug_prompt.py
index 79b64be..72091d0 100644 (file)
@@ -6,16 +6,16 @@ import logging
 
 import telepathy
 
+import constants
+import tp
 import gtk_toolbox
+import gvoice
 
 
 _moduleLogger = logging.getLogger("channel.text")
 
 
-class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
-       """
-       Look into implementing ChannelInterfaceMessages for rich text formatting
-       """
+class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
 
        def __init__(self, connection, manager, props, contactHandle):
                self.__manager = manager
@@ -23,40 +23,12 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
 
                cmd.Cmd.__init__(self, "Debug Prompt")
                self.use_rawinput = False
-               try:
-                       # HACK Older python-telepathy way
-                       telepathy.server.ChannelTypeText.__init__(self, connection, contactHandle)
-                       self._requested = props[telepathy.interfaces.CHANNEL_INTERFACE + '.Requested']
-                       self._implement_property_get(
-                               telepathy.interfaces.CHANNEL_INTERFACE,
-                               {"Requested": lambda: self._requested}
-                       )
-               except TypeError:
-                       # HACK Newer python-telepathy way
-                       telepathy.server.ChannelTypeText.__init__(self, connection, manager, props)
+               tp.ChannelTypeText.__init__(self, connection, manager, props)
                self.__nextRecievedId = 0
                self.__lastMessageTimestamp = datetime.datetime(1, 1, 1)
 
                self.__otherHandle = contactHandle
 
-               # HACK Older python-telepathy doesn't provide this
-               self._immutable_properties = {
-                       'ChannelType': telepathy.server.interfaces.CHANNEL_INTERFACE,
-                       'TargetHandle': telepathy.server.interfaces.CHANNEL_INTERFACE,
-                       'Interfaces': telepathy.server.interfaces.CHANNEL_INTERFACE,
-                       'TargetHandleType': telepathy.server.interfaces.CHANNEL_INTERFACE,
-                       'TargetID': telepathy.server.interfaces.CHANNEL_INTERFACE,
-                       'Requested': telepathy.server.interfaces.CHANNEL_INTERFACE
-               }
-
-       def get_props(self):
-               # HACK Older python-telepathy doesn't provide this
-               props = dict()
-               for prop, iface in self._immutable_properties.items():
-                       props[iface + '.' + prop] = \
-                               self._prop_getters[iface][prop]()
-               return props
-
        @gtk_toolbox.log_exception(_moduleLogger)
        def Send(self, messageType, text):
                if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
@@ -72,17 +44,17 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                finally:
                        self.stdin, self.stdout = oldStdin, oldStdout
 
-               self._report_new_message(currentStdout.getvalue())
+               stdoutData = currentStdout.getvalue().strip()
+               if stdoutData:
+                       self._report_new_message(stdoutData)
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def Close(self):
                self.close()
 
        def close(self):
-               telepathy.server.ChannelTypeText.Close(self)
-               if self.__manager.channel_exists(self.__props):
-                       # HACK Older python-telepathy requires doing this manually
-                       self.__manager.remove_channel(self)
+               _moduleLogger.debug("Closing debug")
+               tp.ChannelTypeText.Close(self)
                self.remove_from_connection()
 
        def _report_new_message(self, message):
@@ -106,6 +78,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_reset_state_machine(self):
+               self._report_new_message("Reset the refreshing state machine")
+
        def do_get_state(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -117,6 +92,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_state(self):
+               self._report_new_message("Print the current state the refreshing state machine is in")
+
        def do_is_authed(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -128,6 +106,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_is_authed(self):
+               self._report_new_message("Print whether logged in to Google Voice")
+
        def do_is_dnd(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -139,6 +120,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_is_dnd(self):
+               self._report_new_message("Print whether Do-Not-Disturb mode enabled on the Google Voice account")
+
        def do_get_account_number(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -150,6 +134,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_account_number(self):
+               self._report_new_message("Print the Google Voice account number")
+
        def do_get_callback_numbers(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -165,6 +152,23 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_callback_numbers(self):
+               self._report_new_message("Print a list of all configured callback numbers")
+
+       def do_get_sane_callback_number(self, args):
+               if args:
+                       self._report_new_message("No arguments supported")
+                       return
+
+               try:
+                       number = gvoice.backend.get_sane_callback(self._conn.session.backend)
+                       self._report_new_message(number)
+               except Exception, e:
+                       self._report_new_message(str(e))
+
+       def help_get_sane_callback_number(self):
+               self._report_new_message("Print the best guess of callback numbers to use")
+
        def do_get_callback_number(self, args):
                if args:
                        self._report_new_message("No arguments supported")
@@ -176,6 +180,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_get_callback_number(self):
+               self._report_new_message("Print the callback number currently enabled")
+
        def do_call(self, args):
                if len(args) != 1:
                        self._report_new_message("Must specify the phone number and only the phone nunber")
@@ -187,6 +194,9 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                except Exception, e:
                        self._report_new_message(str(e))
 
+       def help_call(self):
+               self._report_new_message("\n".join(["call NUMBER", "Initiate a callback, Google forwarding the call to the callback number"]))
+
        def do_send_sms(self, args):
                if 1 < len(args):
                        self._report_new_message("Must specify the phone number and then message")
@@ -198,3 +208,32 @@ class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
                        self._conn.session.backend.send_sms(number, message)
                except Exception, e:
                        self._report_new_message(str(e))
+
+       def help_send_sms(self):
+               self._report_new_message("\n".join(["send_sms NUMBER MESSAGE0 MESSAGE1 ...", "Send an sms to number NUMBER"]))
+
+       def do_version(self, args):
+               if args:
+                       self._report_new_message("No arguments supported")
+                       return
+               self._report_new_message("%s-%s" % (constants.__version__, constants.__build__))
+
+       def help_version(self):
+               self._report_new_message("Prints the version (hint: %s-%s)" % (constants.__version__, constants.__build__))
+
+       def do_get_polling(self, args):
+               if args:
+                       self._report_new_message("No arguments supported")
+                       return
+               self._report_new_message("\n".join((
+                       "Contacts:", repr(self._conn.session.addressbookStateMachine)
+               )))
+               self._report_new_message("\n".join((
+                       "Voicemail:", repr(self._conn.session.voicemailsStateMachine)
+               )))
+               self._report_new_message("\n".join((
+                       "Texts:", repr(self._conn.session.textsStateMachine)
+               )))
+
+       def help_get_polling(self):
+               self._report_new_message("Prints the frequency each of the state machines updates")