1 """
2 Module for synchronization of two sources of type calendar "event".
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 import pickle, os
20 import pisiprogress
21
23 modulesToLoad.sort()
24 modulesNamesCombined = modulesToLoad[0] + modulesToLoad[1]
25 knownEvents = _readModulesPreviousEvents( modulesNamesCombined )
26
27 allEventsLeft = source[0].allEvents()
28 allEventsRight = source[1].allEvents()
29 pisiprogress.getCallback().verbose("")
30 pisiprogress.getCallback().verbose("Module %s has %d events in total" %(modulesToLoad[0], len(allEventsLeft)))
31 pisiprogress.getCallback().verbose("Module %s has %d events in total" %(modulesToLoad[1], len(allEventsRight)))
32 pisiprogress.getCallback().verbose("")
33 for id in allEventsLeft.keys():
34 event = allEventsLeft[id]
35 if not id in allEventsRight.keys():
36
37 if id in knownEvents:
38
39 source[0].removeEvent(id)
40 else:
41
42 source[1].addEvent(event)
43 knownEvents.append(id)
44 else:
45 sameEvent = allEventsRight[id]
46 if not event.compare(sameEvent):
47 if event.updated == "":
48 source[0].replaceEvent( event.id, sameEvent )
49 elif sameEvent.updated == "":
50 source[1].replaceEvent( event.id, event )
51 elif event.updated < sameEvent.updated:
52 source[0].replaceEvent( event.id, sameEvent )
53 elif event.updated > sameEvent.updated:
54 source[1].replaceEvent( sameEvent.id, event )
55 else:
56 pass
57
58 for id in allEventsRight.keys():
59 event = allEventsRight[id]
60 if not id in allEventsLeft.keys():
61
62 if id in knownEvents:
63
64 source[1].removeEvent(id)
65 else:
66 source[0].addEvent( event )
67 knownEvents.append(id)
68
69 _saveModulesNewEvent(modulesNamesCombined, knownEvents)
70
72 """
73 Load, which events were existent already in past, when these two sources were synchronised
74 """
75 homedir = os.environ.get('HOME')
76 configfolder = homedir + '/.pisi/modules/'
77 if not os.path.exists(configfolder):
78 os.mkdir( configfolder )
79 modulesFile = configfolder + moduleNames
80 if not os.path.exists(modulesFile):
81 tmplist = []
82 file = open(modulesFile, 'w')
83 pickle.dump(tmplist, file)
84 file.close()
85 return []
86 file = open(modulesFile, 'r')
87 ret = pickle.load(file)
88 file.close()
89 return ret
90
92 """
93 Save the list of events ids, which have ever been synchronised for these two sources
94 """
95 homedir = os.environ.get('HOME')
96 modulesFile = homedir + '/.pisi/modules/' + moduleNames
97 file = open(modulesFile, 'w')
98 pickle.dump(list, file)
99 file.close()
100