| Trees | Indices | Help |
|
|---|
|
|
1 """
2 Holds classes used for resolving conflicts.
3
4 Copyright: John Stowers, 2006
5 License: GPLv2
6 """
7 import logging
8 log = logging.getLogger("Conflict")
9
10 import conduit
11
12 #ENUM of directions when resolving a conflict
13 CONFLICT_ASK = 0
14 CONFLICT_SKIP = 1
15 CONFLICT_COPY_SOURCE_TO_SINK = 2
16 CONFLICT_COPY_SINK_TO_SOURCE = 3
17 CONFLICT_DELETE = 4
18
20 """
21 Represents a conflict
22 """
23 - def __init__(self, cond, sourceWrapper, sourceData, sourceDataRid, sinkWrapper, sinkData, sinkDataRid, validResolveChoices, isDeletion):
24 self.cond = cond
25 self.sourceWrapper = sourceWrapper
26 self.sourceData = sourceData
27 self.sourceDataRid = sourceDataRid
28 self.sinkWrapper = sinkWrapper
29 self.sinkData = sinkData
30 self.sinkDataRid = sinkDataRid
31 self.choices = validResolveChoices
32 self.isDeletion = isDeletion
33
34 self._gen_hash()
35
37 if self.sourceWrapper and self.sourceDataRid and self.sinkWrapper:
38 mapping = conduit.GLOBALS.mappingDB.get_mapping(
39 sourceUID=self.sourceWrapper.get_UID(),
40 dataLUID=self.sourceDataRid.get_UID(),
41 sinkUID=self.sinkWrapper.get_UID())
42
43 if mapping.oid:
44 self._hash = hash(mapping.oid)
45 return
46
47 #approximate a stable hash for the relationship that is invariant
48 #based upon the order of source and sink
49 uids = [hash(self.sourceWrapper.get_UID()),
50 hash(self.sinkWrapper.get_UID()),
51 hash(self.sourceDataRid),
52 hash(self.sinkDataRid)]
53 uids.sort()
54 self._hash = hash(tuple(uids))
55
58
61
63 if is_source:
64 return self.sourceData.get_snippet()
65 else:
66 return self.sinkData.get_snippet()
67
70
72 resolve = True
73 delete = False
74
75 if direction == CONFLICT_ASK:
76 log.debug("Not resolving")
77 resolve = False
78 elif direction == CONFLICT_SKIP:
79 log.debug("Skipping conflict")
80 resolve = False
81 elif direction == CONFLICT_COPY_SOURCE_TO_SINK:
82 log.debug("Resolving source data --> sink")
83 data = self.sourceData
84 dataRid = self.sourceDataRid
85 source = self.sourceWrapper
86 sink = self.sinkWrapper
87 elif direction == CONFLICT_COPY_SINK_TO_SOURCE:
88 log.debug("Resolving source <-- sink data")
89 data = self.sinkData
90 dataRid = self.sinkDataRid
91 source = self.sinkWrapper
92 sink = self.sourceWrapper
93 elif direction == CONFLICT_DELETE:
94 log.debug("Resolving deletion --->")
95 data = self.sinkData
96 dataRid = self.sinkDataRid
97 source = self.sourceWrapper
98 sink = self.sinkWrapper
99 delete = True
100 else:
101 log.warn("Unknown resolution")
102 resolve = False
103
104 if resolve:
105 if delete:
106 log.debug("Resolving self. Deleting %s from %s" % (data, sink))
107 conduit.Synchronization.delete_data(source, sink, data.get_UID())
108 else:
109 log.debug("Resolving self. Putting %s --> %s" % (data, sink))
110 conduit.Synchronization.put_data(source, sink, data, dataRid, True)
111
112 self.cond.resolved_conflict(self)
113
114 return resolve
115
| Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Sat Aug 2 22:18:52 2008 | http://epydoc.sourceforge.net |