Return all links contained in directory (or any sub directory).

def walk_links(directory, prefix='', linkbase=None):
    """ Return all links contained in directory (or any sub directory).
    """
    links = {}
    try:
        for child in os.listdir(directory):
            fullname = os.path.join(directory, child)
            if os.path.islink(fullname):
                link_path = os.path.normpath(os.path.join(directory, os.readlink(fullname)))
                if linkbase:
                    link_path = os.path.relpath(link_path, linkbase)
                links[os.path.join(prefix, child)] = link_path
            elif os.path.isdir(fullname):
                links.update(walk_links(fullname,
                                        prefix=os.path.join(prefix, child),
                                        linkbase=linkbase))
    except OSError as err:
        if err.errno != 2:  # Ignore unknown directory error
            raise
    return links