class Hermes:
"""Encapsulate the process of syncing online friends' information with the
- Evolution contacts' database. This should be used as follows:
+ Evolution contacts' database.
- * Initialise, passing in a GUI callback.
- * Call Syncjob.
- * Retrieve information on changes effected.
- * Call update_contact to enact manual mapping.
-
Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
Released under the Artistic Licence."""
tick_increment = len(contacts) / (len(to_create) or 1)
print tick_increment, to_create
for friend in to_create:
+ friend.set_source(service.get_id())
self._progress("Creating contacts...", current_tick, total_ticks)
current_tick += tick_increment
self.create_contact_from_friend(friend)
self._progress("Finalising...", current_tick, total_ticks)
current_tick += len(contacts)
service.finalise(self.updated, overwrite_existing_fields)
- self.friends[service.get_id] = service.get_unmatched_friends()
+ for friend in service.get_unmatched_friends():
+ friend.set_source(service.get_id())
+ key = unicode(friend.get_name()).encode('trans') + "_" + service.get_id()
+ self.friends[key] = friend
# commit changes
tick_increment = total_contacts / (len(self.updated) or 1)
# -----------------------------------------------------------------------
- def update_contact(self, contact, friend, resync=False):
+ def update_contact(self, contact, friend, resync=False, commit=False):
"""Update the given contact with information from the given friend."""
print "updating contact ", contact, " with friend ", friend
- self.updated.append(contact)
+ if friend.update_contact(contact, resync):
+ self.updated.append(contact)
+ if commit:
+ self.address_book.commit_contact(contact.get_econtact())
+
self.matched.append(contact)
if friend.get_source() is not None:
contact.add_mapping(friend.get_source())
# -----------------------------------------------------------------------
def _create_empty_contact(self, friend):
econtact = evolution.ebook.EContact()
- econtact.props.full_name = friend['name']
econtact.props.given_name = friend['first_name']
econtact.props.family_name = friend['last_name']
+ econtact.props.full_name = friend.get_name()
+ return econtact
# -----------------------------------------------------------------------
def _create_contact_wrapper(self, econtact):
- return Contact(self.address_book, econtact)
\ No newline at end of file
+ return Contact(self.address_book, econtact)