Trees | Indices | Help |
|
---|
|
1 """ 2 Module for synchronization of two sources of type "contacts". 3 4 This file is part of Pisi. 5 6 Pisi is free software: you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 Pisi is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Pisi. If not, see <http://www.gnu.org/licenses/> 18 """ 19 from pisiconstants import * 20 import pisiprogress 2123 """ 24 Use interaction for choosing which contact entry to keep in case of a conflict 25 26 @return: A dictionary which contains the action for each conflict entry; the key is the id of the contact entry, 27 the value one out of a - keep entry from first source, b - keep value from second source and s - skip this entry (no change on either side) 28 29 The call is passed on to L{pisiprogress.AbstractCallback.askConfirmation} 30 """ 31 return pisiprogress.getCallback().askConfirmation(source, idList)3234 """ 35 Synchronizes two data sources of type 'CONTACT' 36 37 This method is taking the mergeMode into account when deciding about overwriting values (in case of conflicts). 38 39 All contacts entries of one data source are compared against the ones of the other data source. 40 First of all, the ID of the entries is taken into accout for checking, which entries relate to each other. The delta (regarding the IDs) is 41 appended to the other data source. Whenever the IDs are the same for two entries, a deep compare is carried out; all attributes are 42 compared against each other. If there is any difference, the overwrite of a value (or a skip) is performed depending on the merge mode. 43 """ 44 pisiprogress.getCallback().verbose("") 45 pisiprogress.getCallback().verbose("Module %s has %d contacts in total" %(modulesToLoad[0],len(source[0].allContacts()))) 46 pisiprogress.getCallback().verbose("Module %s has %d contacts in total" %(modulesToLoad[1],len(source[1].allContacts()))) 47 48 if mergeMode == MERGEMODE_FLUSH_A: 49 pisiprogress.getCallback().verbose("I am in conflict mode FLUSH source 1 - deleting all (%d) entries on this side now." %(len(source[0].allContacts()))) 50 source[0].flush() 51 if mergeMode == MERGEMODE_FLUSH_B: 52 pisiprogress.getCallback().verbose("I am in conflict mode FLUSH source 2 - deleting all (%d) entries on this side now." %(len(source[1].allContacts()))) 53 source[1].flush() 54 55 commonIDs = {} 56 delta1 = [] 57 delta2 = [] 58 for id1 in source[0].allContacts().keys(): 59 if source[1].allContacts().has_key(id1): 60 commonIDs[id1] = 1 61 else: 62 delta1.append(id1) 63 for id2 in source[1].allContacts().keys(): 64 if not commonIDs.has_key(id2): 65 delta2.append(id2) 66 67 # new, we take the entries where there are common ids and compare them deeply 68 conflicts = [] 69 for key in commonIDs.keys(): 70 if not source[0].getContact(key).compare(source[1].getContact(key)): 71 del commonIDs[key] 72 conflicts.append(key) 73 74 pisiprogress.getCallback().verbose("") 75 pisiprogress.getCallback().verbose("%d entries in common" %(len(commonIDs))) 76 pisiprogress.getCallback().verbose("%d entries with conflicts" %(len(conflicts))) 77 pisiprogress.getCallback().verbose("%d entires in source 1 - but not in 2" %(len(delta1))) 78 pisiprogress.getCallback().verbose("%d entires in source 2 - but not in 1" %(len(delta2))) 79 80 # simple stuff first - add the deltas always to the opposite side 81 for addID in delta1: 82 source[1].addContact(source[0].getContact(addID)) 83 for addID in delta2: 84 source[0].addContact(source[1].getContact(addID)) 85 86 confDict = {} 87 if mergeMode == MERGEMODE_SKIP: 88 pass # leave each side as it is 89 elif mergeMode == MERGEMODE_FLUSH_A or mergeMode == MERGEMODE_FLUSH_B: 90 pass # there shouldn't be anything to do here as there can't be any common instances with a flushed repository 91 else: 92 if mergeMode == MERGEMODE_MANUALCONFIRM: 93 confirmDict = _askConfirmation(source, conflicts) 94 for id in conflicts: 95 if mergeMode == MERGEMODE_OVERWRITE_A: 96 source[0].replaceContact(id, source[1].getContact(id)) 97 if mergeMode == MERGEMODE_OVERWRITE_B: 98 source[1].replaceContact(id, source[0].getContact(id)) 99 if mergeMode == MERGEMODE_MANUALCONFIRM: 100 if confirmDict[id] == 'a': 101 source[1].replaceContact(id, source[0].getContact(id)) 102 elif confirmDict[id] == 'b': 103 source[0].replaceContact(id, source[1].getContact(id)) 104 elif confirmDict[id] == 's': # skip 105 pass106
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Fri Apr 2 09:04:24 2010 | http://epydoc.sourceforge.net |