'Downloads the libraries referred to by a file.
This is done by running ldd on the remote server, parsing the output
and downloading the relevant files.
The directory argument specified where to download the files. This defaults
to \'./$HOSTNAME\' where $HOSTNAME is the hostname of the remote server.'

def libs(self, remote, directory=None):

    libs = self._libs_remote(remote)
    remote = self.readlink('-f', remote).strip()
    libs[remote] = 0
    if (directory == None):
        directory = self.host
    directory = os.path.realpath(directory)
    res = {}
    seen = set()
    for (lib, addr) in libs.items():
        local = os.path.realpath(os.path.join(directory, (('.' + os.path.sep) + lib)))
        if (not local.startswith(directory)):
            self.warning(('This    seems    fishy:    %r' % lib))
            continue
        misc.mkdir_p(os.path.dirname(local))
        if (lib not in seen):
            self.download_file(lib, local)
            seen.add(lib)
        res[local] = addr
    return res
