'Extract tarball into the an directory
This code assume the first (or only) entry is the main directory
:type tarball: string
:param tarball: tarball file path
:type directory: string
:param directory: directory path
:return: path of toplevel directory as extracted from tarball'

def _extract_tarball(self, tarball, directory):

    f = tarfile.open(tarball)
    members = f.getmembers()
    topdir = members[0]
    assert topdir.isdir()
    for m in members:
        f.extract(m, directory)
    return os.path.join(directory, topdir.name)
