(self, tbl, src_fn, dst_fn)
Compare two table dumps, create sql file to fix target table
            or apply changes to target table directly.
Compare two table dumps, create sql file to fix target table
            or apply changes to target table directly.
Compare two table dumps create sql file to fix target table or apply changes to target table directly .
def dump_compare(self, tbl, src_fn, dst_fn):
        """ Compare two table dumps, create sql file to fix target table
            or apply changes to target table directly.
        """
        self.log.info("Comparing dumps: %s", tbl)
        self.cnt_insert = 0
        self.cnt_update = 0
        self.cnt_delete = 0
        self.total_src = 0
        self.total_dst = 0
        f1 = open(src_fn, "r", 64*1024)
        f2 = open(dst_fn, "r", 64*1024)
        src_ln = f1.readline()
        dst_ln = f2.readline()
        if src_ln: self.total_src += 1
        if dst_ln: self.total_dst += 1

        fix = "fix.%s.sql" % tbl
        if os.path.isfile(fix):
            os.unlink(fix)

        while src_ln or dst_ln:
            keep_src = keep_dst = 0
            if src_ln != dst_ln:
                src_row = self.get_row(src_ln)
                dst_row = self.get_row(dst_ln)

                diff = self.cmp_keys(src_row, dst_row)
                if diff > 0:
                    # src > dst
                    self.got_missed_delete(tbl, dst_row)
                    keep_src = 1
                elif diff < 0:
                    # src < dst
                    self.got_missed_insert(tbl, src_row)
                    keep_dst = 1
                else:
                    if self.cmp_data(src_row, dst_row) != 0:
                        self.got_missed_update(tbl, src_row, dst_row)

            if not keep_src:
                src_ln = f1.readline()
                if src_ln: self.total_src += 1
            if not keep_dst:
                dst_ln = f2.readline()
                if dst_ln: self.total_dst += 1

        self.log.info("finished %s: src: %d rows, dst: %d rows,"
                " missed: %d inserts, %d updates, %d deletes",
                tbl, self.total_src, self.total_dst,
                self.cnt_insert, self.cnt_update, self.cnt_delete)
def dump_compare ( self , tbl , src_fn , dst_fn ) : self . log . info ( "Comparing dumps: %s" , tbl ) self . cnt_insert = 0 self . cnt_update = 0 self . cnt_delete = 0 self . total_src = 0 self . total_dst = 0 f1 = open ( src_fn , "r" , 64 * 1024 ) f2 = open ( dst_fn , "r" , 64 * 1024 ) src_ln = f1 . readline ( ) dst_ln = f2 . readline ( ) if src_ln : self . total_src += 1 if dst_ln : self . total_dst += 1 fix = "fix.%s.sql" % tbl if os . path . isfile ( fix ) : os . unlink ( fix ) while src_ln or dst_ln : keep_src = keep_dst = 0 if src_ln != dst_ln : src_row = self . get_row ( src_ln ) dst_row = self . get_row ( dst_ln ) diff = self . cmp_keys ( src_row , dst_row ) if diff > 0 : # src > dst self . got_missed_delete ( tbl , dst_row ) keep_src = 1 elif diff < 0 : # src < dst self . got_missed_insert ( tbl , src_row ) keep_dst = 1 else : if self . cmp_data ( src_row , dst_row ) != 0 : self . got_missed_update ( tbl , src_row , dst_row ) if not keep_src : src_ln = f1 . readline ( ) if src_ln : self . total_src += 1 if not keep_dst : dst_ln = f2 . readline ( ) if dst_ln : self . total_dst += 1 self . log . info ( "finished %s: src: %d rows, dst: %d rows," " missed: %d inserts, %d updates, %d deletes" , tbl , self . total_src , self . total_dst , self . cnt_insert , self . cnt_update , self . cnt_delete )