def calculateconfigdiff(first, second, onlyfirst=True):
    """Calculate differences in configuration between 2 configurations.

       onlyfirst -- only check configuration entries that occur in the first config"""
    add = []
    diff1 = []
    diff2 = []
    remove = []
    for section, item, value in first.walkconfig():
        if not second.hasconfig(section, item):
            add.append((section, item, value))
        elif second.config(section, item) != value:
            diff1.append((section, item, value))
    if not onlyfirst:
        for section, item, value in second.walkconfig():
            if not first.hasconfig(section, item):
                remove.append((section, item, value))
            elif first.config(section, item) != value:
                diff2.append((section, item, value))
    return add, diff1, diff2, remove
