def MultiWaySync(self, accounts): """Perform a multi-way sync between given accounts Args: accounts: List of account nicknames to sync between Returns: None """ cleaned_contacts = [] contacts = [] for account in accounts: self.SelectAccount(account) contacts.extend(self.GetContactList()) duplicates, originals = ceFindDuplicates(contacts) merged, todelete = ceMergeDuplicates(duplicates) cleaned_contacts.extend(originals) cleaned_contacts.extend(merged) for account in accounts: self.SelectAccount(account) self.RemoveAll() for account in accounts: self.SelectAccount(account) for contact in cleaned_contacts: self.BatchEnqueue('create', contact) self.ExecuteBatchQueue()
def OneWaySync(self, from_nickname, to_nickname): """Perform a one-way sync: from_nickname --> to_nickname This method checks for duplicates. Contacts in 'from_account' with a duplicate in 'to_account' will be merged together and saved in 'to_account. Args: from_nickname: Account nickname to sync from to_nickname: Account nickname to sync to Returns: None """ contacts = [] self.SelectAccount(from_nickname) from_contacts = self.GetContactList() self.SelectAccount(to_nickname) to_contacts = self.GetContactList() from_contacts.extend(to_contacts) duplicates, contacts = ceFindDuplicates(from_contacts) merged, todelete = ceMergeDuplicates(duplicates) # contacts: non-duplicate contacts # merged: merged duplicate contacts # todelete: duplicates to delete for contact in todelete: if ceIsOrigin(contact, self.current_account.email): self.BatchEnqueue('delete', contact) self.ExecuteBatchQueue() self.SelectAccount(to_nickname) for contact in contacts: if not ceIsOrigin(contact, self.current_account.email): self.BatchEnqueue('create', contact) self.ExecuteBatchQueue() for contact in merged: if ceIsOrigin(contact, self.current_account.email): self.BatchEnqueue('update', contact) else: self.BatchEnqueue('create', contact) self.ExecuteBatchQueue()