def batch_create(self, src_sl, src_dbid, items): """See the documentation in folder.Folder""" my_dbid = self.get_dbid() c = self.get_config() pname = src_sl.get_pname() src_sync_tag = c.make_sync_label(src_sl.get_pname(), src_dbid) dst_sync_tag = c.make_sync_label(src_sl.get_pname(), my_dbid) f = self.get_db().new_feed() stats = BatchState(1, f, 'insert', sync_tag=dst_sync_tag) success = True for item in items: con_itemid = item.get_itemid_from_synctags(pname, 'gc') gc = GCContact(self, con=item, con_itemid=con_itemid) bid = item.get_itemid() gc.update_sync_tags(src_sync_tag, bid) gce = gc.get_gce() stats.add_con(bid, new=gc, orig=item) f.add_insert(entry=gce, batch_id_string=bid) stats.incr_cnt() if stats.get_cnt() % self.get_batch_size() == 0: # Feeds have to be less than 1MB. We can push this some # more. FIXME. logging.debug( 'Uploading new batch # %02d to Google. ' + 'Count: %3d. Size: %6.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ f = self.get_db().new_feed() stats = BatchState(stats.get_bnum() + 1, f, 'insert', sync_tag=dst_sync_tag) # Upload any leftovers if stats.get_cnt() > 0: logging.debug('New Batch # %02d. Count: %3d. Size: %5.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ return success
def batch_create (self, src_sl, src_dbid, items): """See the documentation in folder.Folder""" my_dbid = self.get_dbid() c = self.get_config() pname = src_sl.get_pname() src_sync_tag = c.make_sync_label(src_sl.get_pname(), src_dbid) dst_sync_tag = c.make_sync_label(src_sl.get_pname(), my_dbid) f = self.get_db().new_feed() stats = BatchState(1, f, 'insert', sync_tag=dst_sync_tag) success = True for item in items: con_itemid = item.get_itemid_from_synctags(pname, 'gc') gc = GCContact(self, con=item, con_itemid=con_itemid) bid = item.get_itemid() gc.update_sync_tags(src_sync_tag, bid) gce = gc.get_gce() stats.add_con(bid, new=gc, orig=item) f.add_insert(entry=gce, batch_id_string=bid) stats.incr_cnt() if stats.get_cnt() % self.get_batch_size() == 0: # Feeds have to be less than 1MB. We can push this some # more. FIXME. logging.debug('Uploading new batch # %02d to Google. ' + 'Count: %3d. Size: %6.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ f = self.get_db().new_feed() stats = BatchState(stats.get_bnum()+1, f, 'insert', sync_tag=dst_sync_tag) # Upload any leftovers if stats.get_cnt() > 0: logging.debug('New Batch # %02d. Count: %3d. Size: %5.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ return success
def batch_update (self, sync_list, src_dbid, items): """See the documentation in folder.Folder""" # Updates and deletes on google require not just the entryid but also # its correct etag which is a version identifier. This is to ensure # two apps do not overwrite each other's work without even knowing # about it. So we need to approach this in two steps: (a) Fetch the # ContactEntries for all the items we are interested in. the returned # entry objects have all the required info, including the latest # etag. (b) Modify the same entry with the local updates and send it # back my_dbid = self.get_dbid() c = self.get_config() pname = sync_list.get_pname() src_sync_tag = c.make_sync_label(pname, src_dbid) dst_sync_tag = c.make_sync_label(pname, my_dbid) tags = [item.get_sync_tags(dst_sync_tag)[0] for item in items] gcids = [val for (tag, val) in tags] logging.debug('Refreshing etags for modified entries...') success, ces = self._fetch_gc_entries(gcids) etags = [copy.deepcopy(ce.etag) for ce in ces] f = self.get_db().new_feed() stats = BatchState(1, f, 'update', sync_tag=dst_sync_tag) for item, etag in zip(items, etags): gc = GCContact(self, con=item) bid = item.get_itemid() gc.update_sync_tags(src_sync_tag, bid) gce = gc.get_gce() gce.etag = etag stats.add_con(bid, new=gc, orig=item) f.add_update(entry=gce, batch_id_string=bid) stats.incr_cnt() if stats.get_cnt() % self.get_batch_size() == 0: # Feeds have to be less than 1MB. We can push this some # more. FIXME. logging.debug('Uploading mod batch # %02d to Google. ' + 'Count: %3d. Size: %6.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ f = self.get_db().new_feed() stats = BatchState(stats.get_bnum()+1, f, 'update', sync_tag=dst_sync_tag) # Upload any leftovers if stats.get_cnt() > 0: logging.debug('Mod Batch # %02d. Count: %3d. Size: %5.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ return success
def batch_update (self, sync_list, src_dbid, items): """See the documentation in folder.Folder""" # Updates and deletes on google require not just the entryid but also # its correct etag which is a version identifier. This is to ensure # two apps do not overwrite each other's work without even knowing # about it. So we need to approach this in two steps: (a) Fetch the # ContactEntries for all the items we are interested in. the returned # entry objects have all the required info, including the latest # etag. (b) Modify the same entry with the local updates and send it # back my_dbid = self.get_dbid() c = self.get_config() pname = sync_list.get_pname() src_sync_tag = c.make_sync_label(pname, src_dbid) dst_sync_tag = c.make_sync_label(pname, my_dbid) tags = [item.get_sync_tags(dst_sync_tag)[0] for item in items] gcids = [val for (tag, val) in tags] logging.debug('Refreshing etags for modified entries...') success, ces = self._fetch_gc_entries(gcids) etags = [copy.deepcopy(ce.etag) for ce in ces] f = self.get_db().new_feed() stats = BatchState(1, f, 'update', sync_tag=dst_sync_tag) for item, etag in zip(items, etags): gc = GCContact(self, con=item) bid = item.get_itemid() gc.update_sync_tags(src_sync_tag, bid) gce = gc.get_gce() gce.etag = etag stats.add_con(bid, new=gc, orig=item) f.add_update(entry=gce, batch_id_string=bid) stats.incr_cnt() if stats.get_cnt() % self.get_batch_size() == 0: # Feeds have to be less than 1MB. We can push this some # more. FIXME. logging.debug('Uploading mod batch # %02d to Google. ' + 'Count: %3d. Size: %6.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ f = self.get_db().new_feed() stats = BatchState(stats.get_bnum()+1, f, 'update', sync_tag=dst_sync_tag) # Upload any leftovers if stats.get_cnt() > 0: logging.debug('Mod Batch # %02d. Count: %3d. Size: %5.2fK', stats.get_bnum(), stats.get_cnt(), stats.get_size()) rf = self.get_db().exec_batch(f) succ, cons = stats.process_batch_response(rf) success = success and succ return success