From 79e7712303c21d02d789b5c8b3ac890516a3c593 Mon Sep 17 00:00:00 2001 From: Krzysztof Klinikowski Date: Tue, 3 Aug 2010 00:45:32 +0200 Subject: Synchronisation with server - initial release. --- sunshine/aliasing.py | 56 ++---------- sunshine/capabilities.py | 2 +- sunshine/channel/contact_list.py | 176 ++------------------------------------ sunshine/channel/group.py | 59 ++----------- sunshine/connection.py | 103 ++++------------------ sunshine/connection_manager.py | 3 +- sunshine/lqsoft/cstruct/common.py | 6 +- sunshine/util/config.py | 55 +----------- 8 files changed, 44 insertions(+), 416 deletions(-) (limited to 'sunshine') diff --git a/sunshine/aliasing.py b/sunshine/aliasing.py index c57cc88..09d8af5 100644 --- a/sunshine/aliasing.py +++ b/sunshine/aliasing.py @@ -55,9 +55,9 @@ class SunshineAliasing(telepathy.server.ConnectionInterfaceAliasing): for handle_id, alias in aliases.iteritems(): handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) if handle == SunshineHandleFactory(self, 'self'): + self.aliases[handle.name] = alias logger.info("Self alias changed to '%s'" % alias) - self.configfile.save_self_alias(alias) - self.AliasesChanged(((SunshineHandleFactory(self, 'self'), alias), )) + self.AliasesChanged([(SunshineHandleFactory(self, 'self'), alias)]) else: logger.debug("Called SetAliases for handle: %s, alias: %s" % (handle.name, alias)) @@ -71,53 +71,26 @@ class SunshineAliasing(telepathy.server.ConnectionInterfaceAliasing): except: pass - #alias = unicode(alias, 'utf-8') logger.info("Contact %s alias changed to '%s'" % (unicode(handle.name), alias)) self.aliases[handle.name] = alias self.AliasesChanged([(handle, alias)]) + self.exportContactsFile() -# # papyon.event.ContactEventInterface -# def on_contact_display_name_changed(self, contact): -# self._contact_alias_changed(contact) -# -# # papyon.event.ContactEventInterface -# def on_contact_infos_changed(self, contact, updated_infos): -# alias = updated_infos.get(ContactGeneral.ANNOTATIONS, {}).\ -# get(ContactAnnotations.NICKNAME, None) -# -# if alias is not None or alias != "": -# self._contact_alias_changed(contact) -# -# # papyon.event.ContactEventInterface -# def on_contact_memberships_changed(self, contact): -# handle = ButterflyHandleFactory(self, 'contact', -# contact.account, contact.network_id) -# if contact.is_member(papyon.Membership.FORWARD): -# alias = handle.pending_alias -# if alias is not None: -# infos = {ContactGeneral.ANNOTATIONS : \ -# {ContactAnnotations.NICKNAME : alias.encode('utf-8')} -# } -# self.msn_client.address_book.\ -# update_contact_infos(contact, infos) -# handle.pending_alias = None - + #@async def _get_alias(self, handle_id): """Get the alias from one handle id""" handle = self.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) if handle == SunshineHandleFactory(self, 'self'): logger.info("SunshineHandleFactory for self handle '%s', id: %s" % (handle.name, handle.id)) - alias = self.configfile.get_self_alias() - self.configfile.save_self_alias(alias) - if alias == None or len(alias) == 0: + if self.aliases.has_key(handle.name): + alias = self.aliases[handle.name] + else: alias = handle.name else: logger.info("SunshineHandleFactory handle '%s', id: %s" % (handle.name, handle.id)) contact = handle.contact - #print str(self.aliases) if self.aliases.has_key(handle.name): alias = self.aliases[handle.name] - #del self.aliases[handle.name] elif contact is None: alias = handle.name else: @@ -126,18 +99,3 @@ class SunshineAliasing(telepathy.server.ConnectionInterfaceAliasing): alias = str(handle.name) return alias -# @async -# def _contact_alias_changed(self, contact): -# handle = GaduHandleFactory(self, 'contact', -# contact.account, None) -# -# alias = contact.infos.get(ContactGeneral.ANNOTATIONS, {}).\ -# get(ContactAnnotations.NICKNAME, None) -# -# if alias == "" or alias is None: -# alias = contact.display_name -# -# alias = unicode(alias, 'utf-8') -# logger.info("Contact %s alias changed to '%s'" % (unicode(handle), alias)) -# self.AliasesChanged([(handle, alias)]) -# diff --git a/sunshine/capabilities.py b/sunshine/capabilities.py index 3d06b5f..80b96d7 100644 --- a/sunshine/capabilities.py +++ b/sunshine/capabilities.py @@ -146,7 +146,7 @@ class SunshineCapabilities(telepathy.server.ConnectionInterfaceCapabilities, def on_contact_client_capabilities_changed(self, contact): self._update_capabilities(contact) - + @async def contactAdded(self, handle): """When we add a contact in our contact list, add the capabilities to create text channel to the contact""" diff --git a/sunshine/channel/contact_list.py b/sunshine/channel/contact_list.py index 0fbf4f3..cc2b321 100644 --- a/sunshine/channel/contact_list.py +++ b/sunshine/channel/contact_list.py @@ -101,7 +101,7 @@ def SunshineContactListChannelFactory(connection, manager, handle, props): props[telepathy.CHANNEL_INTERFACE + '.TargetHandleType'], props[telepathy.CHANNEL_INTERFACE + '.TargetHandle']) - if handle.get_name() == 'subscribe': + if handle.get_name() == 'stored': channel_class = SunshineSubscribeListChannel #hacky & tricky # elif handle.get_name() == 'publish': @@ -136,40 +136,6 @@ class SunshineListChannel( def GetLocalPendingMembersWithInfo(self): return [] - # papyon.event.AddressBookEventInterface - def on_addressbook_contact_added(self, contact): - added = set() - local_pending = set() - remote_pending = set() - - ad, lp, rp = self._filter_contact(contact) - if ad or lp or rp: - handle = ButterflyHandleFactory(self._conn_ref(), 'contact', - contact.account, contact.network_id) - if ad: added.add(handle) - if lp: local_pending.add(handle) - if rp: remote_pending.add(handle) - msg = contact.attributes.get('invite_message', '') - self.MembersChanged(msg, added, (), local_pending, remote_pending, 0, - telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) - - # papyon.event.AddressBookEventInterface - def on_addressbook_contact_deleted(self, contact): - handle = ButterflyHandleFactory(self._conn_ref(), 'contact', - contact.account, contact.network_id) - ad, lp, rp = self._filter_contact(contact) - if self._contains_handle(handle) and not ad: - self.MembersChanged('', (), [handle], (), (), 0, - telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) - - # papyon.event.AddressBookEventInterface - def on_addressbook_contact_blocked(self, contact): - pass - - # papyon.event.AddressBookEventInterface - def on_addressbook_contact_unblocked(self, contact): - pass - @async def _populate(self, connection): added = set() @@ -177,7 +143,6 @@ class SunshineListChannel( remote_pending = set() for contact in connection.gadu_client.contacts: - #logger.info("New contact %s, name: %s added." % (contact.uin, contact.ShowName)) ad, lp, rp = self._filter_contact(contact) if ad or lp or rp: handle = SunshineHandleFactory(self._conn_ref(), 'contact', @@ -187,8 +152,6 @@ class SunshineListChannel( if ad: added.add(handle) if lp: local_pending.add(handle) if rp: remote_pending.add(handle) - #self._conn_ref()._populate_capabilities() - #capabilities for self handle self._conn_ref().contactAdded(self._conn_ref().GetSelfHandle()) self.MembersChanged('', added, (), local_pending, remote_pending, 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) @@ -225,7 +188,6 @@ class SunshineSubscribeListChannel(SunshineListChannel): ET.SubElement(contact_xml, "Groups") c = GaduContact.from_xml(contact_xml) self._conn_ref().gadu_client.addContact( c ) - #config.addNewContact( c ) self._conn_ref().gadu_client.notifyAboutContact( c ) logger.info("Adding contact: %s" % (handle.name)) self.MembersChanged('', [handle], (), (), (), 0, @@ -237,146 +199,20 @@ class SunshineSubscribeListChannel(SunshineListChannel): #and group if self._conn_ref().pending_contacts_to_group.has_key(handle.name): logger.info("Trying to add temporary group.") - #print str(self._conn_ref().pending_contacts_to_group) - #print str(self._conn_ref().pending_contacts_to_group[handle.name]) handle.contact.updateGroups(self._conn_ref().pending_contacts_to_group[handle.name]) self._conn_ref().contactAdded(handle) logger.info("Contact added.") + self._conn_ref().exportContactsFile() def RemoveMembers(self, contacts, message): for h in contacts: - handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h) - contact = handle.contact - self._conn_ref().gadu_client.removeContact(contact, notify=True) + handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, h) + contact = handle.contact + self._conn_ref().gadu_client.removeContact(contact, notify=True) self.MembersChanged('', (), [handle], (), (), 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) + self._conn_ref().exportContactsFile() def _filter_contact(self, contact): return (True, False, False) - #@Lockable(mutex, 'add_subscribe', 'finished_cb') -# def _add(self, handle_id, message, finished_cb): -# logger.info("Subscribe - Add Members called.") -# handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) -# if handle.contact is not None and \ -# handle.contact.is_member(papyon.Membership.FORWARD): -# return True -# -# account = handle.account -# network = handle.network -# groups = list(handle.pending_groups) -# handle.pending_groups = set() -# ab = self._conn.msn_client.address_book -# ab.add_messenger_contact(account, -# network_id=network, -# auto_allow=False, -# invite_message=message.encode('utf-8'), -# groups=groups, -# done_cb=(finished_cb,), -# failed_cb=(finished_cb,)) - - @Lockable(mutex, 'rem_subscribe', 'finished_cb') - def _remove(self, handle_id, finished_cb): - handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) - contact = handle.contact - if contact is None or not contact.is_member(papyon.Membership.FORWARD): - return True - ab = self._conn.msn_client.address_book - ab.delete_contact(contact, done_cb=(finished_cb,), - failed_cb=(finished_cb,)) - - # papyon.event.ContactEventInterface - def on_contact_memberships_changed(self, contact): - handle = ButterflyHandleFactory(self._conn_ref(), 'contact', - contact.account, contact.network_id) - if contact.is_member(papyon.Membership.FORWARD): - self.MembersChanged('', [handle], (), (), (), 0, - telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED) - if len(handle.pending_groups) > 0: - ab = self._conn.msn_client.address_book - for group in handle.pending_groups: - ab.add_contact_to_group(group, contact) - handle.pending_groups = set() - -# -#class ButterflyPublishListChannel(ButterflyListChannel, -# papyon.event.ContactEventInterface): -# -# def __init__(self, connection, manager, props): -# ButterflyListChannel.__init__(self, connection, manager, props) -# papyon.event.ContactEventInterface.__init__(self, connection.msn_client) -# self.GroupFlagsChanged(0, 0) -# -# def AddMembers(self, contacts, message): -# for handle_id in contacts: -# self._add(handle_id, message) -# -# def RemoveMembers(self, contacts, message): -# for handle_id in contacts: -# self._remove(handle_id) -# -# def GetLocalPendingMembersWithInfo(self): -# result = [] -# for contact in self._conn.msn_client.address_book.contacts: -# if not contact.is_member(papyon.Membership.PENDING): -# continue -# handle = ButterflyHandleFactory(self._conn_ref(), 'contact', -# contact.account, contact.network_id) -# result.append((handle, handle, -# telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED, -# contact.attributes.get('invite_message', ''))) -# return result -# -# def _filter_contact(self, contact): -# return (contact.is_member(papyon.Membership.ALLOW), -# contact.is_member(papyon.Membership.PENDING), -# False) -# -# @Lockable(mutex, 'add_publish', 'finished_cb') -# def _add(self, handle_id, message, finished_cb): -# handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) -# contact = handle.contact -# if contact is not None and contact.is_member(papyon.Membership.ALLOW): -# return True -# -# account = handle.account -# network = handle.network -# ab = self._conn.msn_client.address_book -# if contact is not None and contact.is_member(papyon.Membership.PENDING): -# ab.accept_contact_invitation(contact, False, -# done_cb=(finished_cb,), failed_cb=(finished_cb,)) -# else: -# ab.allow_contact(account, network, -# done_cb=(finished_cb,), failed_cb=(finished_cb,)) -# -# @Lockable(mutex, 'rem_publish', 'finished_cb') -# def _remove(self, handle_id, finished_cb): -# handle = self._conn.handle(telepathy.HANDLE_TYPE_CONTACT, handle_id) -# contact = handle.contact -# ab = self._conn.msn_client.address_book -# if contact.is_member(papyon.Membership.PENDING): -# ab.decline_contact_invitation(contact, False, done_cb=finished_cb, -# failed_cb=finished_cb) -# elif contact.is_member(papyon.Membership.ALLOW): -# ab.disallow_contact(contact, done_cb=(finished_cb,), -# failed_cb=(finished_cb,)) -# else: -# return True -# -# # papyon.event.ContactEventInterface -# def on_contact_memberships_changed(self, contact): -# handle = ButterflyHandleFactory(self._conn_ref(), 'contact', -# contact.account, contact.network_id) -# if self._contains_handle(handle): -# if contact.is_member(papyon.Membership.PENDING): -# # Nothing worth our attention -# return -# -# if contact.is_member(papyon.Membership.ALLOW): -# # Contact accepted -# self.MembersChanged('', [handle], (), (), (), 0, -# telepathy.CHANNEL_GROUP_CHANGE_REASON_INVITED) -# else: -# # Contact rejected -# self.MembersChanged('', (), [handle], (), (), 0, -# telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) diff --git a/sunshine/channel/group.py b/sunshine/channel/group.py index 375d07a..d094364 100644 --- a/sunshine/channel/group.py +++ b/sunshine/channel/group.py @@ -26,6 +26,8 @@ import xml.etree.ElementTree as ET from sunshine.lqsoft.pygadu.models import GaduProfile, GaduContact, GaduContactGroup +from twisted.internet import reactor + from sunshine.util.decorator import async from sunshine.handle import SunshineHandleFactory from sunshine.channel.contact_list import SunshineListChannel @@ -87,7 +89,7 @@ class SunshineGroupChannel(SunshineListChannel): group = self._handle.group self.add_contact_to_group(group, contact, contact_handle) - + reactor.callLater(3.0, self._conn_ref().exportContactsFile) def RemoveMembers(self, contacts, message): for contact_handle_id in contacts: @@ -100,63 +102,12 @@ class SunshineGroupChannel(SunshineListChannel): group = self._handle.group self.delete_contact_from_group(group, contact, contact_handle) + reactor.callLater(3.0, self._conn.exportContactsFile) + def Close(self): logger.debug("Deleting group %s" % self._handle.name) del self.conn.profile.groups[self._handle.name] -# ab = self._conn.msn_client.address_book -# group = self._handle.group -# ab.delete_group(group) - -# def _filter_contact(self, contact): -# if contact.is_member(papyon.Membership.FORWARD): -# for group in contact.groups: -# if group.name.decode("utf-8") == self._handle.name: -# return (True, False, False) -# return (False, False, False) -# -# def on_addressbook_group_added(self, group): -# if group.name.decode("utf-8") == self._handle.name: -# self.AddMembers(self.__pending_add, None) -# self.__pending_add = [] -# self.RemoveMembers(self.__pending_remove, None) -# self.__pending_remove = [] -# -# def on_addressbook_group_deleted(self, group): -# if group.name.decode("utf-8") == self._handle.name: -# self.Closed() -# self._conn.remove_channel(self) -# -# def on_addressbook_group_contact_added(self, group, contact): -# group_name = group.name.decode("utf-8") -# if group_name == self._handle.name: -# handle = ButterflyHandleFactory(self._conn_ref(), 'contact', -# contact.account, contact.network_id) -# -# added = set() -# added.add(handle) -# -# self.MembersChanged('', added, (), (), (), 0, -# telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) -# -# logger.debug("Contact %s added to group %s" % -# (handle.name, group_name)) -# -# def on_addressbook_group_contact_deleted(self, group, contact): -# group_name = group.name.decode("utf-8") -# if group_name == self._handle.name: -# handle = ButterflyHandleFactory(self._conn_ref(), 'contact', -# contact.account, contact.network_id) -# -# removed = set() -# removed.add(handle) -# -# self.MembersChanged('', (), removed, (), (), 0, -# telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE) -# -# logger.debug("Contact %s removed from group %s" % -# (handle.name, group_name)) -# @async def add_contact_to_group(self, group, contact, contact_handle): diff --git a/sunshine/connection.py b/sunshine/connection.py index b0880e3..8e491fc 100644 --- a/sunshine/connection.py +++ b/sunshine/connection.py @@ -87,24 +87,12 @@ class GaduClientFactory(protocol.ClientFactory): def clientConnectionLost(self, connector, reason): logger.info('Lost connection. Reason: %s' % (reason)) - if self.config.contactsLoop != None: - self.config.contactsLoop.stop() - self.config.contactsLoop = None - if self.config.exportLoop != None: - self.config.exportLoop.stop() - self.config.exportLoop = None if reactor.running: reactor.stop() os._exit(1) def clientConnectionFailed(self, connector, reason): logger.info('Connection failed. Reason: %s' % (reason)) - if self.config.contactsLoop != None: - self.config.contactsLoop.stop() - self.config.contactsLoop = None - if self.config.exportLoop != None: - self.config.exportLoop.stop() - self.config.exportLoop = None if reactor.running: reactor.stop() os._exit(1) @@ -129,14 +117,12 @@ class SunshineConnection(telepathy.server.Connection, _optional_parameters = { 'server' : 's', 'port' : 'q', - 'export-contacts' : 'b', 'use-ssl' : 'b', 'use-specified-server' : 'b' } _parameter_defaults = { 'server' : '91.197.13.67', 'port' : 8074, - 'export-contacts' : False, 'use-ssl' : True, 'use-specified-server' : False } @@ -151,7 +137,6 @@ class SunshineConnection(telepathy.server.Connection, self._manager = weakref.proxy(manager) self._account = (parameters['account'], parameters['password']) self.param_server = (parameters['server'], parameters['port']) - self._export_contacts = bool(parameters['export-contacts']) self.param_use_ssl = bool(parameters['use-ssl']) self.param_specified_server = bool(parameters['use-specified-server']) @@ -168,26 +153,7 @@ class SunshineConnection(telepathy.server.Connection, self.profile.onXmlEvent = self.onXmlEvent self.profile.onUserData = self.onUserData - #lets try to make file with contacts etc ^^ self.configfile = SunshineConfig(int(parameters['account'])) - self.configfile.check_dirs() - #lets get contacts from contacts config file - contacts_list = self.configfile.get_contacts() - - for contact_from_list in contacts_list['contacts']: - c = GaduContact.from_xml(contact_from_list) - try: - c.uin - self.profile.addContact(c) - except: - pass - - for group_from_list in contacts_list['groups']: - g = GaduContactGroup.from_xml(group_from_list) - if g.Name: - self.profile.addGroup(g) - - logger.info("We have %s contacts in file." % (self.configfile.get_contacts_count())) self.factory = GaduClientFactory(self.profile) self.ggapi = GG_Oauth(self.profile.uin, parameters['password']) @@ -198,12 +164,12 @@ class SunshineConnection(telepathy.server.Connection, self._conf_id = 0 self.pending_contacts_to_group = {} self._status = None - self.profile.contactsLoop = None # Call parent initializers telepathy.server.Connection.__init__(self, 'gadugadu', account, 'sunshine') telepathy.server.ConnectionInterfaceRequests.__init__(self) SunshinePresence.__init__(self) + SunshineAliasing.__init__(self) SunshineAvatars.__init__(self) SunshineCapabilities.__init__(self) SunshineContactInfo.__init__(self) @@ -270,17 +236,13 @@ class SunshineConnection(telepathy.server.Connection, self.getServerAdress(self._account[0]) def Disconnect(self): - if self.profile.contactsLoop: - self.profile.contactsLoop.stop() - self.profile.contactsLoop = None - if self._export_contacts == True: - if self.profile.exportLoop: - self.profile.exportLoop.stop() - self.profile.exportLoop = None - - #if self._status == telepathy.CONNECTION_STATUS_DISCONNECTED: - # self.profile.disconnect() - # self.factory.disconnect() + #if self.profile.contactsLoop: + # self.profile.contactsLoop.stop() + # self.profile.contactsLoop = None + #if self._export_contacts == True: + # if self.profile.exportLoop: + # self.profile.exportLoop.stop() + # self.profile.exportLoop = None self.StatusChanged(telepathy.CONNECTION_STATUS_DISCONNECTED, telepathy.CONNECTION_STATUS_REASON_REQUESTED) @@ -357,24 +319,24 @@ class SunshineConnection(telepathy.server.Connection, _success(channel._object_path) self.signal_new_channels([channel]) - #@async def updateContactsFile(self): """Method that updates contact file when it changes and in loop every 5 seconds.""" - self.configfile.make_contacts_file(self.profile.groups, self.profile.contacts) + return self.configfile.make_contacts_file(self.profile.groups, self.profile.contacts) - #@async def exportContactsFile(self): logger.info("Exporting contacts.") - file = open(self.configfile.path, "r") - contacts_xml = file.read() - file.close() + print "self.profile.groups:", self.profile.groups + print "self.profile.contacts:", self.profile.contacts + contacts_xml = self.updateContactsFile() + print "contacts_xml:", contacts_xml + if len(contacts_xml) != 0: self.profile.exportContacts(contacts_xml) @async def makeTelepathyContactsChannel(self): logger.debug("Method makeTelepathyContactsChannel called.") - handle = SunshineHandleFactory(self, 'list', 'subscribe') + handle = SunshineHandleFactory(self, 'list', 'stored') props = self._generate_props(telepathy.CHANNEL_TYPE_CONTACT_LIST, handle, False) self._channel_manager.channel_for_props(props, signal=True) @@ -431,20 +393,10 @@ class SunshineConnection(telepathy.server.Connection, #self.factory.disconnect() def on_contactsImported(self): - logger.info("No contacts in the XML contacts file yet. Contacts imported.") - - #self.configfile.make_contacts_file(self.profile.groups, self.profile.contacts) - self.profile.contactsLoop = task.LoopingCall(self.updateContactsFile) - self.profile.contactsLoop.start(5.0, True) - - if self._export_contacts == True: - self.profile.exportLoop = task.LoopingCall(self.exportContactsFile) - self.profile.exportLoop.start(30.0) + logger.info("Contacts imported.") self.makeTelepathyContactsChannel() self.makeTelepathyGroupChannels() - - SunshineAliasing.__init__(self) self._status = telepathy.CONNECTION_STATUS_CONNECTED self.StatusChanged(telepathy.CONNECTION_STATUS_CONNECTED, @@ -453,28 +405,7 @@ class SunshineConnection(telepathy.server.Connection, def on_loginSuccess(self): logger.info("Connected") - #if its a first run or we dont have any contacts in contacts file yet then try to import contacts from server - if self.configfile.get_contacts_count() == 0: - self.profile.importContacts(self.on_contactsImported) - else: - #self.configfile.make_contacts_file(self.profile.groups, self.profile.contacts) - self.profile.contactsLoop = task.LoopingCall(self.updateContactsFile) - self.profile.contactsLoop.start(5.0, True) - - if self._export_contacts == True: - self.profile.exportLoop = task.LoopingCall(self.exportContactsFile) - self.profile.exportLoop.start(30.0) - - self.makeTelepathyContactsChannel() - self.makeTelepathyGroupChannels() - - SunshineAliasing.__init__(self) - - self._status = telepathy.CONNECTION_STATUS_CONNECTED - self.StatusChanged(telepathy.CONNECTION_STATUS_CONNECTED, - telepathy.CONNECTION_STATUS_REASON_REQUESTED) - #self._populate_capabilities() - #self.contactAdded(self.GetSelfHandle()) + self.profile.importContacts(self.on_contactsImported) def on_loginFailed(self, response): logger.info("Login failed: ", response) diff --git a/sunshine/connection_manager.py b/sunshine/connection_manager.py index b2d99c5..7fba6d5 100644 --- a/sunshine/connection_manager.py +++ b/sunshine/connection_manager.py @@ -84,6 +84,7 @@ class SunshineConnectionManager(telepathy.server.ConnectionManager): def quit(self): "Terminates all connections. Must be called upon quit" - for connection in self._connections: + conns = self._connections.copy() + for connection in conns: connection.Disconnect() logger.info("Connection manager quitting") diff --git a/sunshine/lqsoft/cstruct/common.py b/sunshine/lqsoft/cstruct/common.py index b4824e9..7c07401 100755 --- a/sunshine/lqsoft/cstruct/common.py +++ b/sunshine/lqsoft/cstruct/common.py @@ -228,14 +228,14 @@ class CStruct(object): dp = ItemWrapper(dict) for field in cls._field_order: - print "Unpacking field @%d: %s" % (offset, field.name) + #print "Unpacking field @%d: %s" % (offset, field.name) value, next_offset = field.unpack(dp, data, offset) dict[field.name] = value offset = next_offset - print "Unpacked: " + repr(value) + #print "Unpacked: " + repr(value) instance = cls(**dict) - print "Unpacked: " + str(instance) + #print "Unpacked: " + str(instance) return instance, offset def __field_value(self, field, default=None): diff --git a/sunshine/util/config.py b/sunshine/util/config.py index 9a3adf5..3fa300e 100644 --- a/sunshine/util/config.py +++ b/sunshine/util/config.py @@ -16,44 +16,6 @@ class SunshineConfig(object): self.contacts_len = 0 self.groups_len = 0 - def check_dirs(self): - path = os.path.join(os.path.join(os.environ['HOME'], '.telepathy-sunshine'), str(self.uin)) - try: - os.makedirs(path) - except: - pass - if not os.path.isfile(os.path.join(path, 'profile.xml')): - contactbook_xml = ET.Element("ContactBook") - - ET.SubElement(contactbook_xml, "Groups") - ET.SubElement(contactbook_xml, "Contacts") - - main_xml = ET.ElementTree(contactbook_xml) - main_xml.write(os.path.join(path, 'profile.xml'), encoding="UTF-8") - - self.path = os.path.join(path, 'profile.xml') - self.path2 = os.path.join(path, 'alias') - return os.path.join(path, 'profile.xml') - - def get_contacts(self): - self.roster = {'groups':[], 'contacts':[]} - try: - file = open(self.path, "r") - config_xml = ET.parse(file).getroot() - - for elem in config_xml.find('Groups').getchildren(): - self.roster['groups'].append(elem) - - for elem in config_xml.find('Contacts').getchildren(): - self.roster['contacts'].append(elem) - - self.contacts_count = len(config_xml.find('Contacts').getchildren()) - - return self.roster - except: - self.contacts_count = 0 - return self.roster - def make_contacts_file(self, groups, contacts): contactbook_xml = ET.Element("ContactBook") @@ -85,22 +47,11 @@ class SunshineConfig(object): ET.SubElement(contact_avatars_xml, "URL").text = "" ET.SubElement(contact_xml, "FlagNormal").text = "true" - main_xml = ET.ElementTree(contactbook_xml) + #main_xml = ET.ElementTree(contactbook_xml) if self.contacts_len >= 0 and self.groups_len >= 0: - main_xml.write(self.path, encoding="UTF-8") + #main_xml.write(self.path, encoding="UTF-8") + return "%s\n%s" % ("", ET.tostring(contactbook_xml)) def get_contacts_count(self): return self.contacts_count - # alias config - def get_self_alias(self): - if os.path.exists(self.path2): - file = open(self.path2, "r") - alias = file.read() - file.close() - return alias - - def save_self_alias(self, alias): - file = open(self.path2, "w") - file.write(alias) - file.close() -- cgit v1.2.3