--- /dev/null
+from __future__ import with_statement
+
+import socket
+import logging
+
+import telepathy
+
+import constants
+import tp
+import gtk_toolbox
+
+
+_moduleLogger = logging.getLogger("channel.debug_log")
+
+
+class DebugLogChannel(tp.ChannelTypeFileTransfer):
+
+ def __init__(self, connection, manager, props, contactHandle):
+ self.__manager = manager
+ self.__props = props
+ self.__otherHandle = contactHandle
+
+ tp.ChannelTypeFileTransfer.__init__(self, connection, manager, props)
+
+ dbus_interface = telepathy.CHANNEL_TYPE_FILE_TRANSFER
+ self._implement_property_get(
+ dbus_interface,
+ {
+ 'State': self.get_state,
+ "ContentType": self.get_content_type,
+ "Filename": self.get_filename,
+ "Size": self.get_state,
+ "Description": self.get_description,
+ "AvailableSocketTypes": self.get_available_socket_types,
+ "TransferredBytes": self.get_transferred_bytes,
+ "InitialOffset": self.get_initial_offset,
+ },
+ )
+
+ # grab a snapshot of the log so that we are always in a consistent
+ # state between calls
+ with open(constants._user_logpath_, "r") as f:
+ logLines = f.xreadlines()
+ self._log = "".join(logLines)
+ self._transferredBytes = 0
+
+ self._state = telepathy.constants.FILE_TRANSFER_STATE_PENDING
+ self.FileTransferStateChanged(
+ self._state,
+ telepathy.constants.FILE_TRANSFER_STATE_CHANGE_REASON_NONE,
+ )
+
+ def get_state(self):
+ return self._state
+
+ def get_content_type(self):
+ return "application/octet-stream"
+
+ def get_filename(self):
+ return "%s.log" % constants._telepathy_implementation_name_
+
+ def get_size(self):
+ return len(self._log)
+
+ def get_description(self):
+ return "Debug log for The One Ring"
+
+ def get_available_socket_types(self):
+ return {
+ telepathy.constants.SOCKET_ADDRESS_TYPE_UNIX: [
+ telepathy.constants.SOCKET_ACCESS_CONTROL_LOCALHOST,
+ telepathy.constants.SOCKET_ACCESS_CONTROL_CREDENTIALS,
+ ],
+ }
+
+ def get_transferred_bytes(self):
+ return self._transferredBytes
+
+ def get_initial_offset(self):
+ return 0
+
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def AcceptFile(self, addressType, accessControl, accessControlParam, offset):
+ _moduleLogger.info("%r %r %r %r" % (addressType, accessControl, accessControlParam, offset))
+ self.InitialOffsetDefined(0)
+ self._state = telepathy.constants.FILE_TRANSFER_STATE_ACCEPTED
+ self.FileTransferStateChanged(
+ self._state,
+ telepathy.constants.FILE_TRANSFER_STATE_CHANGE_REASON_REQUESTED,
+ )
+
+ self._state = telepathy.constants.FILE_TRANSFER_STATE_OPEN
+ self.FileTransferStateChanged(
+ self._state,
+ telepathy.constants.FILE_TRANSFER_STATE_CHANGE_REASON_NONE,
+ )
+
+ sockittome = socket.socket(socket.AF_UNIT, socket.SOCK_STREAM)
+ sockittome.connect(accessControlParam)
+ try:
+ sockittome.send(self._log)
+ finally:
+ sockittome.close()
+
+ self._transferredBytes = len(self._log)
+ self.TransferredBytesChanged(self._transferredBytes)
+
+ self._state = telepathy.constants.FILE_TRANSFER_STATE_COMPLETED
+ self.FileTransferStateChanged(
+ self._state,
+ telepathy.constants.FILE_TRANSFER_STATE_CHANGE_REASON_NONE,
+ )
+
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def ProvideFile(self, addressType, accessControl, accessControlParam):
+ raise telepathy.errors.NotImplemented("Cannot send outbound files")
+
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def Close(self):
+ self.close()
+
+ def close(self):
+ _moduleLogger.debug("Closing log")
+ tp.ChannelTypeFileTransfer.Close(self)
+ self.remove_from_connection()
import gvoice
-_moduleLogger = logging.getLogger("channel.text")
+_moduleLogger = logging.getLogger("channel.debug_prompt")
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
+ publishProps = self._conn._generate_props(telepathy.CHANNEL_TYPE_FILE_TRANSFER, self.__otherHandle, False)
+ self._conn._channel_manager.channel_for_props(publishProps, signal=True)
+
+ 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")
tp.ChannelManager.__init__(self, connection)
fixed = {
+ telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST
+ }
+ self._implement_channel_class(
+ telepathy.CHANNEL_TYPE_CONTACT_LIST,
+ self._get_list_channel,
+ fixed,
+ []
+ )
+
+ fixed = {
telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_TEXT,
telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
}
)
fixed = {
- telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_CONTACT_LIST
+ telepathy.CHANNEL_INTERFACE + '.ChannelType': telepathy.CHANNEL_TYPE_FILE_TRANSFER,
+ telepathy.CHANNEL_INTERFACE + '.TargetHandleType': dbus.UInt32(telepathy.HANDLE_TYPE_CONTACT)
}
self._implement_channel_class(
- telepathy.CHANNEL_TYPE_CONTACT_LIST,
- self._get_list_channel,
+ telepathy.CHANNEL_TYPE_FILE_TRANSFER,
+ self._get_file_transfer_channel,
fixed,
[]
)
chan = channel.text.TextChannel(self._conn, self, props, h)
return chan
+ def _get_file_transfer_channel(self, props):
+ _, surpress_handler, h = self._get_type_requested_handle(props)
+
+ _moduleLogger.debug('New file transfer channel')
+ chan = channel.debug_log.DebugLogChannel(self._conn, self, props, h)
+ return chan
+
def _get_media_channel(self, props):
_, surpress_handler, h = self._get_type_requested_handle(props)