Translate rope.base.change.Change instances to dictionaries.

    See Refactor.get_changes for an explanation of the resulting
    dictionary.

def translate_changes(initial_change):
    """Translate rope.base.change.Change instances to dictionaries.

    See Refactor.get_changes for an explanation of the resulting
    dictionary.

    """
    agenda = [initial_change]
    result = []
    while agenda:
        change = agenda.pop(0)
        if isinstance(change, rope_change.ChangeSet):
            agenda.extend(change.changes)
        elif isinstance(change, rope_change.ChangeContents):
            result.append({'action': 'change',
                           'file': change.resource.real_path,
                           'contents': change.new_contents,
                           'diff': change.get_description()})
        elif isinstance(change, rope_change.CreateFile):
            result.append({'action': 'create',
                           'type': 'file',
                           'file': change.resource.real_path})
        elif isinstance(change, rope_change.CreateFolder):
            result.append({'action': 'create',
                           'type': 'directory',
                           'path': change.resource.real_path})
        elif isinstance(change, rope_change.MoveResource):
            result.append({'action': 'move',
                           'type': ('directory'
                                    if change.new_resource.is_folder()
                                    else 'file'),
                           'source': change.resource.real_path,
                           'destination': change.new_resource.real_path})
        elif isinstance(change, rope_change.RemoveResource):
            if change.resource.is_folder():
                result.append({'action': 'delete',
                               'type': 'directory',
                               'path': change.resource.real_path})
            else:
                result.append({'action': 'delete',
                               'type': 'file',
                               'file': change.resource.real_path})
    return result