'Writes oplog progress to file provided by user'

def write_oplog_progress(self):

    if (self.oplog_checkpoint is None):
        return None
    with self.oplog_progress as oplog_prog:
        oplog_dict = oplog_prog.get_dict()
    items = [[name, util.bson_ts_to_long(oplog_dict[name])] for name in oplog_dict]
    if (not items):
        return
    backup_file = (self.oplog_checkpoint + '.backup')
    os.rename(self.oplog_checkpoint, backup_file)
    with open(self.oplog_checkpoint, 'w') as dest:
        if (len(items) == 1):
            json_str = json.dumps(items[0])
        else:
            json_str = json.dumps(items)
        try:
            dest.write(json_str)
        except IOError:
            dest.truncate()
            with open(backup_file, 'r') as backup:
                shutil.copyfile(backup, dest)
    os.remove(backup_file)
