1 """
2 Shared API for comparing the previous state of a dp to the current
3 state. Returns only changes to core synch mechanism.
4
5 This class is a proxy for the TwoWay dataprovider. If the dataprovider
6 cannot implement get_changes() using backend dependant means this class
7 uses the mapping DB to implement get_changes()
8
9 This class will always be slower than if the backend implements the function
10 iteself.
11
12 Copyright: John Stowers, 2006
13 License: GPLv2
14 """
15 import logging
16 log = logging.getLogger("DeltaProvider")
17
18 import conduit
19
22 self.me = dpw
23 self.other = otherdpw
24
25 log.info("Delta: Source (%s) does not implement get_changes(). Proxying..." % self.me.get_UID())
26
28 """
29 @returns: added, modified, deleted
30 """
31 allItems = []
32 for i in self.me.module.get_all():
33
34
35 if type(i) != unicode:
36 i = unicode(i,errors='replace')
37 allItems.append(i)
38
39 log.debug("Delta: Got %s items\n%s" % (len(allItems), allItems))
40
41
42
43 rids = {}
44 for m in conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(self.me.get_UID(), self.other.get_UID()):
45 rids[ m.get_source_rid().get_UID() ] = m.get_source_rid()
46 for m in conduit.GLOBALS.mappingDB.get_mappings_for_dataproviders(self.other.get_UID(), self.me.get_UID()):
47 rids[ m.get_sink_rid().get_UID() ] = m.get_sink_rid()
48
49 log.debug("Delta: Expecting %s items" % len(rids))
50 for uid,rid in rids.items():
51 log.debug("%s) -- %s" % (uid,rid))
52
53
54
55
56 modified = []
57 for i in allItems[:]:
58 if i in rids:
59 data = self.me.module.get(i)
60 if data.get_rid() != rids[i]:
61 log.debug("Modified: Actual:%s v DB:%s" % (data.get_rid(), rids[i]))
62 modified.append(i)
63 del(rids[i])
64 allItems.remove(i)
65
66
67
68 return allItems, modified, rids.keys()
69