def load(self): """ Load all data from backend """ pisiprogress.getCallback().verbose("Evolution: Loading") pisiprogress.getCallback().progress.push(0, 100) file = bsddb.hashopen(self._path) pisiprogress.getCallback().update("Loading") amount = len(file.keys()) i = 0 for key in file.keys(): data = file[key] # print data if not data.startswith("BEGIN:VCARD"): continue comps = vobject.readComponents( data[: len(data) - 1] ) # there is some problem with a traling white space in each entry for x in comps: # print x.n.value.given atts = extractVcfEntry(x) id = contacts.assembleID(atts) c = contacts.Contact(id, atts) self._allContacts[id] = c self._rawData[id] = x self._edsIDs[id] = key i += 1 pisiprogress.getCallback().progress.setProgress((i * 100) / amount) pisiprogress.getCallback().update("Loading") pisiprogress.getCallback().progress.drop()
def load(self): """ Loads all attributes for all contact entries from the SyncML backend For each entry a new L{contacts.contacts.Contact} instance is created and stored in the instance dictionary L{contacts.AbstractContactSynchronizationModule._allContacts}. For data parsing (VCF) the tools layer in L{vobjecttools} is used. """ pisiprogress.getCallback().progress.push(0, 100) pisiprogress.getCallback().verbose("SyncML: Loading") if_contacts = SyncmlModule.SyncmlContactsInterface(self._url, self._username, self._password, self._database, SYNCMLSERVER_IDENTIFIER) contacts_raw = if_contacts.downloadItems() # load if_contacts.finish() pisiprogress.getCallback().progress.setProgress(20) pisiprogress.getCallback().update("Loading") i = 0 for x in contacts_raw.keys(): content = vobject.readComponents(contacts_raw[x]) for y in content: atts = vobjecttools.extractVcfEntry(y) id = contacts.assembleID(atts) c = contacts.Contact(id, atts) self._allContacts[id] = c self._mapping[id] = x i += 1 pisiprogress.getCallback().progress.setProgress(20 + ((i*80) / len(contacts_raw))) pisiprogress.getCallback().update('Loading') pisiprogress.getCallback().progress.drop()
def load(self): """ Loads all attributes for all contact items from LDAP repository For each entry a new L{contacts.contacts.Contact} instance is created and stored in the instance dictionary L{contacts.AbstractContactSynchronizationModule._allContacts}. """ pisiprogress.getCallback().verbose("LDAP: Loading") l = ldap.initialize("ldap://" + self._ldapHost) l.simple_bind_s(self._ldapUser,self._ldapPassword) res = l.search_s(self._ldapDomain, ldap.SCOPE_SUBTREE, self._ldapFilter) l.unbind() pisiprogress.getCallback().progress.setProgress(20) # we guess that the actual query took up 20 % of the time - the remaining 80 % are taken by parsing the content ... pisiprogress.getCallback().update('Loading') i=0 for cn, contactEntry in res: atts = {} atts['firstname'] = self._extractAtt(contactEntry, "givenName") atts['middlename'] = self._extractAtt(contactEntry, "mozillaNickname") atts['lastname'] = self._extractAtt(contactEntry,"sn") atts['title'] = self._extractAtt(contactEntry,"title") atts['email'] = self._extractAtt(contactEntry,"mail") atts['mobile'] = self._extractAtt(contactEntry,"mobile") atts['phone'] = self._extractAtt(contactEntry,"homePhone") atts['officePhone'] = self._extractAtt(contactEntry,"telephoneNumber") atts['fax'] = self._extractAtt(contactEntry,"facsimileTelephoneNumber") atts['homeStreet'] = self._extractAtt(contactEntry, "mozillaHomeStreet") atts['homePostalCode'] = self._extractAtt(contactEntry, "mozillaHomePostalCode") atts['homeCity'] = self._extractAtt(contactEntry, "mozillaHomeLocalityName") atts['homeCountry'] = self._extractAtt(contactEntry, "mozillaHomeCountryName") atts['homeState'] = self._extractAtt(contactEntry, "mozillaHomeState") atts['businessOrganisation'] = self._extractAtt(contactEntry, "o") atts['businessDepartment'] = self._extractAtt(contactEntry, "ou") atts['businessPostalCode'] = self._extractAtt(contactEntry, "postalCode") atts['businessStreet'] = self._extractAtt(contactEntry, "street") atts['businessCity'] = self._extractAtt(contactEntry, "l") atts['businessCountry'] = self._extractAtt(contactEntry, "c") atts['businessState'] = self._extractAtt(contactEntry, "st") id = contacts.assembleID(atts) c = contacts.Contact(id, atts) self._allContacts[id] = c i+=1 pisiprogress.getCallback().progress.setProgress(20 + ((i*80) / len(res))) pisiprogress.getCallback().update('Loading')
def load(self): """ Loads all attributes for all contact entries from the OPIMD backend For each entry a new L{contacts.contacts.Contact} instance is created and stored in the instance dictionary L{contacts.AbstractContactSynchronizationModule._allContacts}. """ pisiprogress.getCallback().verbose("OPIMD: Loading") bus = dbus.SystemBus(mainloop = e_dbus.DBusEcoreMainLoop()) dbusObject = bus.get_object(BUSNAME, PATH_CONTACTS) contactsInterface = dbus.Interface(dbusObject, dbus_interface= INTERFACE_CONTACTS) query = contactsInterface.Query({}) dbusObject = bus.get_object(BUSNAME, query) query = dbus.Interface(dbusObject, dbus_interface=INTERFACE_QUERY) count = query.GetResultCount() pisiprogress.getCallback().progress.setProgress(20) # we guess that the actual query took up 20 % of the time - the remaining 80 % are taken by parsing the content ... pisiprogress.getCallback().update('Loading') i=0 for contact in query.GetMultipleResults(count): atts = {} dbusObject = bus.get_object(BUSNAME, contact.get('Path')) contactObject = dbus.Interface(dbusObject, dbus_interface= INTERFACE_CONTACT) self._extractValue(atts, 'firstname', contactObject, 'Name') self._extractValue(atts, 'middlename', contactObject, 'Middlename') self._extractValue(atts, 'lastname', contactObject, 'Surname') self._extractValue(atts, 'email', contactObject, 'E-mail') self._extractValue(atts, 'mobile', contactObject, 'Phone') if not atts['mobile']: self._extractValue(atts, 'mobile', contactObject, 'Mobile phone') self._extractValue(atts, 'phone', contactObject, 'Home phone') self._extractValue(atts, 'officePhone', contactObject, 'Work phone') self._extractValue(atts, 'fax', contactObject, 'Fax phone') self._extractValue(atts, 'title', contactObject, 'Title') self._extractValue(atts, 'businessOrganisation', contactObject, 'Organisation') self._extractValue(atts, 'businessDepartment', contactObject, 'Departement') self._extractValue(atts, 'businessStreet', contactObject, 'BusinessStreet') self._extractValue(atts, 'businessPostalCode', contactObject, 'BusinessPostalCode') self._extractValue(atts, 'businessCity', contactObject, 'BusinessCity') self._extractValue(atts, 'businessCountry', contactObject, 'BusinessCountry') self._extractValue(atts, 'businessState', contactObject, 'BusinessState') self._extractValue(atts, 'homeStreet', contactObject, 'HomeStreet') self._extractValue(atts, 'homePostalCode', contactObject, 'HomePostalCode') self._extractValue(atts, 'homeCity', contactObject, 'HomeCity') self._extractValue(atts, 'homeCountry', contactObject, 'HomeCountry') self._extractValue(atts, 'homeState', contactObject, 'HomeState') id = contacts.assembleID(atts) c = contacts.Contact(id, atts) self._allContacts[id] = c self._idMappingGlobalInternal[id] = contact.get('Path') self._idMappingInternalGlobal[contact.get('Path')] = id i+=1 pisiprogress.getCallback().progress.setProgress(20 + ((i*80) / count)) pisiprogress.getCallback().update('Loading')
def load(self): """ Load all data from backend """ pisiprogress.getCallback().verbose ("DBUS_SIM: Loading") pisiprogress.getCallback().progress.push(0, 100) pisiprogress.getCallback().verbose (" >SIM Card Limitations: %d entries maximum; no more than %d characters per name" %(self._max_simentries, self._name_maxlength)) bus = dbus.SystemBus() gsm_device_obj = bus.get_object(DBUS_GSM_DEVICE[0], DBUS_GSM_DEVICE[1]) sim = dbus.Interface(gsm_device_obj,DBUS_SIM) dbusContacts = sim.RetrievePhonebook(DBUS_CONTACTS, 1, self._max_simentries) pisiprogress.getCallback().progress.setProgress(20) pisiprogress.getCallback().update("Loading") i = 0 for c in dbusContacts: dbus_id = c[0] name = c[1] number = c[2] del self._availableIds[dbus_id] type = PHONE_TYPE_MOBILE if name.endswith(DBUS_NAME_MOBILEPHONE_SUFFIX): name = name[:len(name) - len(DBUS_NAME_MOBILEPHONE_SUFFIX)] if name.endswith(DBUS_NAME_WORKPHONE_SUFFIX): type = PHONE_TYPE_WORK name = name[:len(name) - len(DBUS_NAME_WORKPHONE_SUFFIX)] elif name.endswith(DBUS_NAME_HOMEPHONE_SUFFIX): type = PHONE_TYPE_HOME name = name[:len(name) - len(DBUS_NAME_HOMEPHONE_SUFFIX)] atts = {} title, first, last, middle = pisitools.parseFullName(name) atts['title'] = title atts['firstname'] = first atts['lastname'] = last atts['middlename'] = middle id = contacts.assembleID(atts) if self._allContacts.has_key(id): c = self._allContacts[id] if type == PHONE_TYPE_MOBILE: c.attributes['mobile'] = number.strip() elif type == PHONE_TYPE_WORK: c.attributes['officePhone'] = number.strip() elif type == PHONE_TYPE_HOME: c.attributes['phone'] = number.strip() else: if type == PHONE_TYPE_MOBILE: atts['mobile'] = number.strip() elif type == PHONE_TYPE_WORK: atts['officePhone'] = number.strip() elif type == PHONE_TYPE_HOME: atts['phone'] = number.strip() c = contacts.Contact(id, atts) self._allContacts[id] = c self._idMappings[id] = [] self._idMappings[id].append(dbus_id) i+=1 pisiprogress.getCallback().progress.setProgress(20 + ((i*80) / len(dbusContacts))) pisiprogress.getCallback().update('Loading') pisiprogress.getCallback().progress.drop()
def load(self): """ Loads all attributes for all contact entries from the SQLite database For each entry a new L{contacts.contacts.Contact} instance is created and stored in the instance dictionary L{contacts.AbstractContactSynchronizationModule._allContacts}. Several requests to the database are executed in order to get all the detailled information about phone numbers and addresses, etc. as well. """ pisiprogress.getCallback().verbose("SQLite: Loading") database = sqlite3.connect(self._dbpath, isolation_level=None) db_call = "select recid, firstname, middlename, lastname, company, title, department from contacts" contactEntries = database.execute(db_call).fetchall() pisiprogress.getCallback().progress.setProgress(20) # we guess that the actual query took up 20 % of the time - the remaining 80 % are taken by parsing the content ... pisiprogress.getCallback().update('Loading') i=0 for contactEntry in contactEntries: atts = {} recid = contactEntry[0] atts['firstname'] = contactEntry[1] atts['middlename'] = contactEntry[2] atts['lastname'] = contactEntry[3] atts['businessOrganisation'] = contactEntry[4] atts['title'] = contactEntry[5] atts['businessDepartment'] = contactEntry[6] # fetch detail information as well db_call = "select phone_number, phone_type from contactphonenumbers where recid = %s" %(recid) phoneEntries = database.execute(db_call).fetchall() for phoneEntry in phoneEntries: type = int(phoneEntry[1]) if type == QTOPIADB_PHONETYPE_MOBILE or type == QTOPIADB_PHONETYPE_MOBILE_PRIVATE or type == QTOPIADB_PHONETYPE_MOBILE_WORK: atts['mobile'] = phoneEntry[0] elif type == QTOPIADB_PHONETYPE_HOME: atts['phone'] = phoneEntry[0] elif type == QTOPIADB_PHONETYPE_OFFICE: atts['officePhone'] = phoneEntry[0] elif type == QTOPIADB_PHONETYPE_FAX: atts['fax'] = phoneEntry[0] db_call = "select addr from emailaddresses where recid = %s" %(recid) emailEntries = database.execute(db_call).fetchall() for emailEntry in emailEntries: atts['email'] = emailEntry[0] db_call = "select street, city, state, zip, country, addresstype from contactaddresses where recid = %s" %(recid) addressEntries = database.execute(db_call).fetchall() for addressEntry in addressEntries: type = int(addressEntry[5]) if type == QTOPIADB_ADDRESSTYPE_PRIVATE: atts['homeStreet'] = addressEntry[0] atts['homeCity'] = addressEntry[1] atts['homeState'] = addressEntry[2] atts['homePostalCode'] = addressEntry[3] atts['homeCountry'] = addressEntry[4] if type == QTOPIADB_ADDRESSTYPE_BUSINESS: atts['businessStreet'] = addressEntry[0] atts['businessCity'] = addressEntry[1] atts['businessState'] = addressEntry[2] atts['businessPostalCode'] = addressEntry[3] atts['businessCountry'] = addressEntry[4] id = contacts.assembleID(atts) c = contacts.Contact(id, atts) self._allContacts[id] = c self._idMappingGlobalInternal[id] = recid self._idMappingInternalGlobal[recid] = id i+=1 pisiprogress.getCallback().progress.setProgress(20 + ((i*80) / len(contactEntries))) pisiprogress.getCallback().update('Loading') database.close()
def load(self): """ Load all data from backend A single query is performed and the result set is parsed afterwards. """ pisiprogress.getCallback().verbose("Google Contacts: Loading") query = gdata.contacts.service.ContactsQuery() query.max_results = GOOGLE_CONTACTS_MAXRESULTS feed = self._gd_client.GetContactsFeed(query.ToUri()) pisiprogress.getCallback().progress.setProgress(20) # we guess that the actual query took up 20 % of the time - the remaining 80 % are taken by parsing the content ... pisiprogress.getCallback().update('Loading') count = 0 inTotal = len(feed.entry) for i, entry in enumerate(feed.entry): atts = {} if not entry.title or not entry.title.text: pisiprogress.getCallback().verbose('** In Googlecontacts account is an entry with no title - I cannot process this account and will skip it.') continue # an entry without a title cannot be processed by PISI as the name is the 'primary key' self._unpackGoogleTitle(atts, entry.title.text.decode("utf-8")) if len(entry.email) > 0: email = entry.email[0] # for email in entry.email: if email.primary and email.primary == 'true': # for now we only support one email address if email.address: atts['email'] = email.address.decode("utf-8") for phone in entry.phone_number: if phone.rel == gdata.contacts.PHONE_HOME: atts['phone'] = phone.text if phone.rel == gdata.contacts.PHONE_MOBILE: atts['mobile'] = phone.text if phone.rel == gdata.contacts.PHONE_WORK: atts['officePhone'] = phone.text if phone.rel == gdata.contacts.PHONE_WORK_FAX: atts['fax'] = phone.text for address in entry.postal_address: if address.text: value = address.text.decode("utf-8") type = None if address.rel == gdata.contacts.REL_HOME: type = 'home' elif address.rel == gdata.contacts.REL_WORK: type = 'work' if type: self._unpackGooglePostalAddress(atts, value, type) if entry.organization: if entry.organization.org_name and entry.organization.org_name.text: atts['businessOrganisation'] = entry.organization.org_name.text.decode("utf-8") if entry.organization.org_title and entry.organization.org_title.text: atts['businessDepartment'] = entry.organization.org_title.text.decode("utf-8") # well - that doesn't map fully - but better than nothing :) id = contacts.assembleID(atts) c = contacts.Contact(id, atts) self._allContacts[id] = c count+=1 pisiprogress.getCallback().progress.setProgress(20 + ((count*80) / inTotal)) pisiprogress.getCallback().update('Loading') self._idMappingGlobalInternal[id] = entry.GetEditLink().href self._idMappingInternalGlobal[entry.GetEditLink().href] = id