From c1299d00ddbb17aa0bf8826f9f6e98d0a756c16f Mon Sep 17 00:00:00 2001 From: Ed Page Date: Sat, 26 Sep 2009 18:40:25 -0500 Subject: [PATCH] Random cleanup/implementation fairy of fun --- src/channel/text.py | 2 +- src/connection.py | 20 +++++++++++++++----- src/connection_manager.py | 33 ++++++++++++++++----------------- src/constants.py | 2 ++ src/simple_presence.py | 2 +- src/telepathy-theonering | 14 +++++++------- 6 files changed, 42 insertions(+), 31 deletions(-) diff --git a/src/channel/text.py b/src/channel/text.py index e6cc6af..84f9c99 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -6,7 +6,7 @@ import telepathy import handle -class ButterflyTextChannel( +class TheOneRingChannelText( telepathy.server.ChannelTypeText, telepathy.server.ChannelInterfaceGroup, telepathy.server.ChannelInterfaceChatState diff --git a/src/connection.py b/src/connection.py index 2dce28a..9563899 100644 --- a/src/connection.py +++ b/src/connection.py @@ -11,17 +11,26 @@ import channel_manager class TheOneRingConnection(telepathy.server.Connection): - _mandatory_parameters = { + MANDATORY_PARAMETERS = { 'account' : 's', 'password' : 's' } + OPTIONAL_PARAMETERS = { + } + PARAMETER_DEFAULTS = { + } def __init__(self, manager, parameters): try: self.check_parameters(parameters) account = unicode(parameters['account']) - telepathy.server.Connection.__init__(self, 'gvoice', account, 'theonering') + telepathy.server.Connection.__init__( + self, + constants._telepathy_protocol_name_, + account, + constants._telepathy_implementation_name_ + ) self._manager = weakref.proxy(manager) self._credentials = ( @@ -36,8 +45,6 @@ class TheOneRingConnection(telepathy.server.Connection): self.set_self_handle(handle.create_handle(self, 'self')) self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED - self._initial_presence = None - self._initial_personal_message = None logging.info("Connection to the account %s created" % account) except Exception, e: @@ -66,7 +73,10 @@ class TheOneRingConnection(telepathy.server.Connection): """ logging.info("Connecting") self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_NONE_SPECIFIED - self._backend.login(*self._credentials) + try: + self._backend.login(*self._credentials) + except RuntimeError: + self.__disconnect_reason = telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED def Disconnect(self): """ diff --git a/src/connection_manager.py b/src/connection_manager.py index dfcb91a..63e943a 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -3,52 +3,51 @@ import logging import gobject import telepathy +import constants import connection class TheOneRingConnectionManager(telepathy.server.ConnectionManager): def __init__(self, shutdown_func=None): - telepathy.server.ConnectionManager.__init__(self, 'theonering') + telepathy.server.ConnectionManager.__init__(self, constants._telepathy_implementation_name_) - self._protos['gvoice'] = connection.TheOneRingConnection + self._protos[constants._telepathy_protocol_name_] = connection.TheOneRingConnection self._on_shutdown = shutdown_func logging.info("Connection manager created") def GetParameters(self, proto): """ - org.freedesktop.telepathy.ConnectionManager - @returns the mandatory and optional parameters for creating a connection """ if proto not in self._protos: raise telepathy.NotImplemented('unknown protocol %s' % proto) result = [] - connection_class = self._protos[proto] - mandatory_parameters = connection_class._mandatory_parameters - optional_parameters = connection_class._optional_parameters - default_parameters = connection_class._parameter_defaults + ConnectionClass = self._protos[proto] + mandatoryParameters = ConnectionClass.MANDATORY_PARAMETERS + optionalParameters = ConnectionClass.OPTIONAL_PARAMETERS + defaultParameters = ConnectionClass.PARAMETER_DEFAULTS - for parameter_name, parameter_type in mandatory_parameters.iteritems(): + for parameterName, parameterType in mandatoryParameters.iteritems(): param = ( - parameter_name, + parameterName, telepathy.CONN_MGR_PARAM_FLAG_REQUIRED, - parameter_type, + parameterType, '', ) result.append(param) - for parameter_name, parameter_type in optional_parameters.iteritems(): - if parameter_name in default_parameters: + for parameterName, parameterType in optionalParameters.iteritems(): + if parameterName in defaultParameters: param = ( - parameter_name, + parameterName, telepathy.CONN_MGR_PARAM_FLAG_HAS_DEFAULT, - parameter_name, - default_parameters[parameter_name], + parameterName, + defaultParameters[parameterName], ) else: - param = (parameter_name, 0, parameter_name, '') + param = (parameterName, 0, parameterName, '') result.append(param) return result diff --git a/src/constants.py b/src/constants.py index d1bc9a0..8c24289 100644 --- a/src/constants.py +++ b/src/constants.py @@ -7,3 +7,5 @@ __build__ = 0 __app_magic__ = 0xdeadbeef _data_path_ = os.path.join(os.path.expanduser("~"), ".telepathy-theonering") _user_settings_ = "%s/settings.ini" % _data_path_ +_telepathy_protocol_name_ = "gvoice" +_telepathy_implementation_name_ = "theonering" diff --git a/src/simple_presence.py b/src/simple_presence.py index 44e5c50..cd36856 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -13,7 +13,7 @@ class TheOneRingPresence(object): } -class ButterflySimplePresence(telepathy.server.ConnectionInterfaceSimplePresence): +class TheOneRingSimplePresence(telepathy.server.ConnectionInterfaceSimplePresence): def __init__(self): telepathy.server.ConnectionInterfaceSimplePresence.__init__(self) diff --git a/src/telepathy-theonering b/src/telepathy-theonering index a32d3db..33decda 100755 --- a/src/telepathy-theonering +++ b/src/telepathy-theonering @@ -45,13 +45,13 @@ def run_theonering(): manager.quit() mainloop.quit() + def timeout_cb(): + if len(manager._connections) == 0: + logging.info('No connection received - quitting') + quit() + return False - if 'BUTTERFLY_PERSIST' not in os.environ: - def timeout_cb(): - if len(manager._connections) == 0: - logging.info('No connection received - quitting') - quit() - return False + if 'THEONERING_PERSIST' not in os.environ: gobject.timeout_add(IDLE_TIMEOUT, timeout_cb) shutdown_callback = quit else: @@ -75,6 +75,6 @@ def run_theonering(): if __name__ == '__main__': - telepathy_utils.debug_divert_messages(os.getenv('BUTTERFLY_LOGFILE')) + telepathy_utils.debug_divert_messages(os.getenv('THEONERING_LOGFILE')) logging.basicConfig(level=logging.DEBUG) run_theonering() -- 1.7.9.5