import telepathy
import gtk_toolbox
+import util.misc as util_misc
import handle
if phonenumber is None or phonenumber is "":
return ""
- phonenumber = handle.strip_number(phonenumber)
+ phonenumber = util_misc.strip_number(phonenumber)
if len(phonenumber) < 3:
return phonenumber
return
# Update callback
- uglyNumber = handle.strip_number(userHandleAndAlias[1])
+ uglyNumber = util_misc.strip_number(userHandleAndAlias[1])
self.session.backend.set_callback_number(uglyNumber)
# Inform of change
import contact_list
import text
import call
+import debug_prompt
--- /dev/null
+import cmd
+import StringIO
+import time
+import datetime
+import logging
+
+import telepathy
+
+import gtk_toolbox
+
+
+_moduleLogger = logging.getLogger("channel.text")
+
+
+class DebugPromptChannel(telepathy.server.ChannelTypeText, cmd.Cmd):
+ """
+ Look into implementing ChannelInterfaceMessages for rich text formatting
+ """
+
+ def __init__(self, connection, manager, props, contactHandle):
+ self._manager = manager
+ self._props = props
+
+ cmd.Cmd.__init__(self, "Debug Prompt")
+ self.use_rawinput = False
+ try:
+ # HACK Older python-telepathy way
+ telepathy.server.ChannelTypeText.__init__(self, connection, contactHandle)
+ except TypeError:
+ # HACK Newer python-telepathy way
+ telepathy.server.ChannelTypeText.__init__(self, connection, manager, props)
+ self._nextRecievedId = 0
+ self._lastMessageTimestamp = datetime.datetime(1, 1, 1)
+
+ self._otherHandle = contactHandle
+
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def Send(self, messageType, text):
+ if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
+ raise telepathy.errors.NotImplemented("Unhandled message type: %r" % messageType)
+
+ self.Sent(int(time.time()), messageType, text)
+
+ oldStdin, oldStdout = self.stdin, self.stdout
+ try:
+ self.stdin = currentStdin = StringIO.StringIO()
+ self.stdout = currentStdout = StringIO.StringIO()
+ self.onecmd(text)
+ finally:
+ self.stdin, self.stdout = oldStdin, oldStdout
+
+ self._report_new_message(currentStdout.getvalue().strip())
+
+ @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)
+ self.remove_from_connection()
+
+ def _report_new_message(self, message):
+ currentReceivedId = self._nextRecievedId
+
+ timestamp = int(time.time())
+ type = telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL
+
+ self.Received(currentReceivedId, timestamp, self._otherHandle, type, 0, message)
+
+ self._nextRecievedId += 1
+
+ def do_reset_state_machine(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ self._conn.session.stateMachine.reset_timers()
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_get_state(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ state = self._conn.session.stateMachine.get_state()
+ self._report_new_message(str(state))
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_is_authed(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ isAuthed = self._conn.session.backend.is_authed()
+ self._report_new_message(str(isAuthed))
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_is_dnd(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ isDnd = self._conn.session.backend.is_dnd()
+ self._report_new_message(str(isDnd))
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_get_account_number(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ number = self._conn.session.backend.get_account_number()
+ self._report_new_message(number)
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_get_callback_numbers(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ numbers = self._conn.session.backend.get_callback_numbers()
+ numbersDisplay = "\n".join(
+ "%s: %s" % (name, number)
+ for (number, name) in numbers.iteritems()
+ )
+ self._report_new_message(numbersDisplay)
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_get_callback_number(self, args):
+ if args:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ number = self._conn.session.backend.get_callback_number()
+ self._report_new_message(number)
+ except Exception, e:
+ self._report_new_message(str(e))
+
+ def do_call(self, args):
+ if len(args) != 1:
+ self._report_new_message("No arguments supported")
+ return
+
+ try:
+ number = args[0]
+ self._conn.session.backend.call(number)
+ except Exception, e:
+ self._report_new_message(str(e))
try:
mergedConversations = self._conn.session.conversations.get_conversation(self._contactKey)
except KeyError:
- pass
+ _moduleLogger.info("Nothing in the conversation yet for %r" % (self._contactKey, ))
else:
self._report_conversation(mergedConversations)
import telepathy
import channel
+import util.misc as util_misc
_moduleLogger = logging.getLogger("channel_manager")
)
def _get_list_channel(self, props):
- _, surpress_handler, handle = self._get_type_requested_handle(props)
+ _, surpress_handler, h = self._get_type_requested_handle(props)
_moduleLogger.debug('New contact list channel')
- chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, handle)
+ chan = channel.contact_list.create_contact_list_channel(self._conn, self, props, h)
return chan
def _get_text_channel(self, props):
- _, surpress_handler, handle = self._get_type_requested_handle(props)
+ _, surpress_handler, h = self._get_type_requested_handle(props)
- _moduleLogger.debug('New text channel')
- chan = channel.text.TextChannel(self._conn, self, props, handle)
+ accountNumber = util_misc.strip_number(self._conn.session.backend.get_account_number())
+ if h.phoneNumber == accountNumber:
+ _moduleLogger.debug('New Debug channel')
+ chan = channel.debug_prompt.DebugPromptChannel(self._conn, self, props, h)
+ else:
+ _moduleLogger.debug('New text channel')
+ _moduleLogger.info('%r %r' % (accountNumber, h.phoneNumber))
+ chan = channel.text.TextChannel(self._conn, self, props, h)
return chan
def _get_media_channel(self, props):
- _, surpress_handler, handle = self._get_type_requested_handle(props)
+ _, surpress_handler, h = self._get_type_requested_handle(props)
_moduleLogger.debug('New media channel')
- chan = channel.call.CallChannel(self._conn, self, props, handle)
+ chan = channel.call.CallChannel(self._conn, self, props, h)
return chan
import logging
import util.coroutines as coroutines
+import util.misc as util_misc
_moduleLogger = logging.getLogger("gvoice.addressbook")
self._populate_contact_details(contactId)
return self._get_contact_details(contactId)
+ def find_contacts_with_number(self, queryNumber):
+ strippedQueryNumber = util_misc.strip_number(queryNumber)
+ for contactId, (contactName, contactDetails) in self.get_contacts():
+ for phoneType, number in contactDetails:
+ if number == strippedQueryNumber:
+ yield contactId
+
def _populate_contacts(self):
if self._contacts:
return
for contactId, contactDetails in contacts:
contactName = contactDetails["name"]
contactNumbers = [
- (numberDetails.get("phoneType", "Mobile"), numberDetails["phoneNumber"])
+ (
+ numberDetails.get("phoneType", "Mobile"),
+ util_misc.strip_number(numberDetails["phoneNumber"]),
+ )
for numberDetails in contactDetails["numbers"]
]
self._contacts[contactId] = (contactName, contactNumbers)
import logging
import util.coroutines as coroutines
+import util.misc as util_misc
_moduleLogger = logging.getLogger("gvoice.conversations")
conversations = list(self._backend.get_conversations())
conversations.sort()
for conversation in conversations:
- key = conversation.contactId, conversation.number
+ key = conversation.contactId, util_misc.strip_number(conversation.number)
try:
mergedConversations = self._conversations[key]
except KeyError:
import telepathy
+import util.misc as util_misc
+
_moduleLogger = logging.getLogger("handle")
self.profile = connection.username
-def strip_number(prettynumber):
- """
- function to take a phone number and strip out all non-numeric
- characters
-
- >>> strip_number("+012-(345)-678-90")
- '01234567890'
- """
- import re
- uglynumber = re.sub('\D', '', prettynumber)
- return uglynumber
-
-
class ContactHandle(TheOneRingHandle):
def __init__(self, connection, id, contactId, phoneNumber):
TheOneRingHandle.__init__(self, connection, id, handleType, handleName)
self._contactId = contactId
- self._phoneNumber = phoneNumber
+ self._phoneNumber = util_misc.strip_number(phoneNumber)
@staticmethod
def from_handle_name(handleName):
else:
raise RuntimeError("Invalid handle: %s" % handleName)
- contactNumber = strip_number(contactNumber)
+ contactNumber = util_misc.strip_number(contactNumber)
return contactId, contactNumber
@staticmethod
def to_handle_name(contactId, contactNumber):
- handleName = "#".join((contactId, strip_number(contactNumber)))
+ handleName = "#".join((contactId, util_misc.strip_number(contactNumber)))
return handleName
@property
for key in (x for x in f_locals.keys() if x not in saved):
del f_locals[key]
del frame
+
+
+def strip_number(prettynumber):
+ """
+ function to take a phone number and strip out all non-numeric
+ characters
+
+ >>> strip_number("+012-(345)-678-90")
+ '01234567890'
+ """
+ import re
+ uglynumber = re.sub('\D', '', prettynumber)
+ return uglynumber