Added detection of missed calls. As part of this I moved some of the connections...
[theonering] / src / channel / debug_prompt.py
index 72091d0..6b7cebc 100644 (file)
@@ -1,3 +1,6 @@
+from __future__ import with_statement
+
+import os
 import cmd
 import StringIO
 import time
@@ -12,7 +15,7 @@ import gtk_toolbox
 import gvoice
 
 
-_moduleLogger = logging.getLogger("channel.text")
+_moduleLogger = logging.getLogger("channel.debug_prompt")
 
 
 class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
@@ -68,18 +71,32 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
                self.__nextRecievedId += 1
 
        def do_reset_state_machine(self, args):
-               if args:
-                       self._report_new_message("No arguments supported")
-                       return
-
                try:
-                       for machine in self._conn.session.stateMachine._machines:
-                               machine.reset_timers()
+                       args = args.strip().lower()
+                       if not args:
+                               args  = "all"
+                       if args == "all":
+                               for machine in self._conn.session.stateMachine._machines:
+                                       machine.reset_timers()
+                       elif args == "contacts":
+                               self._conn.session.addressbookStateMachine.reset_timers()
+                       elif args == "voicemail":
+                               self._conn.session.voicemailsStateMachine.reset_timers()
+                       elif args == "texts":
+                               self._conn.session.textsStateMachine.reset_timers()
+                       else:
+                               self._report_new_message('Unknown machine "%s"' % (args, ))
                except Exception, e:
                        self._report_new_message(str(e))
 
        def help_reset_state_machine(self):
-               self._report_new_message("Reset the refreshing state machine")
+               self._report_new_message("""Reset the refreshing state machine.
+"reset_state_machine" - resets all
+"reset_state_machine all"
+"reset_state_machine contacts"
+"reset_state_machine voicemail"
+"reset_state_machine texts"
+""")
 
        def do_get_state(self, args):
                if args:
@@ -184,12 +201,12 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
                self._report_new_message("Print the callback number currently enabled")
 
        def do_call(self, args):
-               if len(args) != 1:
+               if not args:
                        self._report_new_message("Must specify the phone number and only the phone nunber")
                        return
 
                try:
-                       number = args[0]
+                       number = args
                        self._conn.session.backend.call(number)
                except Exception, e:
                        self._report_new_message(str(e))
@@ -198,6 +215,7 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
                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):
+               args = args.split(" ")
                if 1 < len(args):
                        self._report_new_message("Must specify the phone number and then message")
                        return
@@ -237,3 +255,36 @@ class DebugPromptChannel(tp.ChannelTypeText, cmd.Cmd):
 
        def help_get_polling(self):
                self._report_new_message("Prints the frequency each of the state machines updates")
+
+       def do_grab_log(self, args):
+               if args:
+                       self._report_new_message("No arguments supported")
+                       return
+
+               try:
+                       publishProps = self._conn.generate_props(telepathy.CHANNEL_TYPE_FILE_TRANSFER, self.__otherHandle, False)
+                       self._conn._channel_manager.channel_for_props(publishProps, signal=True)
+               except Exception, e:
+                       self._report_new_message(str(e))
+
+       def help_grab_log(self):
+               self._report_new_message("Download the debug log for including with bug report")
+               self._report_new_message("Warning: this may contain sensitive information")
+
+       def do_save_log(self, args):
+               if not args:
+                       self._report_new_message("Must specify a filename to save the log to")
+                       return
+
+               try:
+                       filename = os.path.expanduser(args)
+                       with open(constants._user_logpath_, "r") as f:
+                               logLines = f.xreadlines()
+                               log = "".join(logLines)
+                       with open(filename, "w") as f:
+                               f.write(log)
+               except Exception, e:
+                       self._report_new_message(str(e))
+
+       def help_save_log(self):
+               self._report_new_message("Save the log to a specified location")