1 """
2 Sync contact information with Evolution on a Desktop.
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
20 from contacts import contacts
21 from pisiconstants import *
22 import pisiprogress
23
24 import bsddb
25 import vobject
26 from vobjecttools import *
27 import random
28
30 - def __init__( self, modulesString, config, configsection, folder, verbose=False, soft=False):
31 """
32 Constructor
33
34 Super class constructor (L{contacts.AbstractContactSynchronizationModule.__init__}) is called.
35 Local variables are initialized.
36 The settings from the configuration file are loaded.
37
38 @param modulesString: is a small string to help you make a unique id. It is the two modules configuration-names concatinated.
39 @param config: is the configuration from ~/.pisi/conf. Use like config.get(configsection,'user')
40 @param configsection: is the configuration from ~/.pisi/conf. Use like config.get(configsection,'user')
41 @param folder: is a string with the location for where your module can save its own files if necessary
42 @param verbose: should make your module "talk" more
43 @param soft: should tell you if you should make changes (ie. save)
44 """
45 contacts.AbstractContactSynchronizationModule.__init__(self, verbose, soft, modulesString, config, configsection, "Contacts Evolution")
46 self.verbose = verbose
47 self._path = config.get(configsection,'path')
48 self._rawData = {}
49 self._edsIDs = {}
50 pisiprogress.getCallback().verbose("Evolution contacts module loaded")
51
52
82
84 """
85 IDs from EDS look like being a 16 digit Hex String
86 """
87 st = ""
88 for i in range (16):
89 k = random.randint(0, 15)
90 if k > 9:
91 st += chr(k + 55)
92 else:
93 st += str(k)
94 return 'pas-id-' + st
95
97
98 try:
99 eds_id = self._edsIDs[id]
100 except KeyError:
101 eds_id = self._generateEDS_ID()
102 self._edsIDs[id] = eds_id
103 jid = j.add('uid')
104 jid.value = eds_id
105
106
107 try:
108 for addr in j.contents['adr']:
109 try:
110 pos = addr.params['TYPE'].index('POSTAL')
111 del addr.params['TYPE'][pos]
112 except ValueError:
113 pass
114 except KeyError:
115 pass
116
117
118 try:
119 for tel in j.contents['tel']:
120 try:
121 pos = tel.params['TYPE'].index('VOICE')
122 del tel.params['TYPE'][pos]
123 except ValueError:
124 pass
125 except KeyError:
126 pass
127
128
129 return eds_id
130
136
138 key = self._edsIDs[id]
139 del file[key]
140
144
169