def extract_tarball(spec, filename, allow_root=False, unsigned=False, force=False):
    '\n    extract binary tarball for given package into install area\n    '
    if os.path.exists(spec.prefix):
        if force:
            shutil.rmtree(spec.prefix)
        else:
            raise NoOverwriteException(str(spec.prefix))
    tmpdir = tempfile.mkdtemp()
    stagepath = os.path.dirname(filename)
    spackfile_name = tarball_name(spec, '.spack')
    spackfile_path = os.path.join(stagepath, spackfile_name)
    tarfile_name = tarball_name(spec, '.tar.gz')
    tarfile_path = os.path.join(tmpdir, tarfile_name)
    specfile_name = tarball_name(spec, '.spec.yaml')
    specfile_path = os.path.join(tmpdir, specfile_name)
    with closing(tarfile.open(spackfile_path, 'r')) as tar:
        tar.extractall(tmpdir)
    if (not os.path.exists(tarfile_path)):
        tarfile_name = tarball_name(spec, '.tar.bz2')
        tarfile_path = os.path.join(tmpdir, tarfile_name)
    if (not unsigned):
        if os.path.exists(('%s.asc' % specfile_path)):
            try:
                suppress = config.get('config:suppress_gpg_warnings', False)
                Gpg.verify(('%s.asc' % specfile_path), specfile_path, suppress)
            except Exception as e:
                shutil.rmtree(tmpdir)
                raise e
        else:
            shutil.rmtree(tmpdir)
            raise NoVerifyException('Package spec file failed signature verification.\nUse spack buildcache keys to download and install a key for verification from the mirror.')
    checksum = checksum_tarball(tarfile_path)
    spec_dict = {}
    with open(specfile_path, 'r') as inputfile:
        content = inputfile.read()
        spec_dict = syaml.load(content)
    bchecksum = spec_dict['binary_cache_checksum']
    if (bchecksum['hash'] != checksum):
        shutil.rmtree(tmpdir)
        raise NoChecksumException('Package tarball failed checksum verification.\nIt cannot be installed.')
    new_relative_prefix = str(os.path.relpath(spec.prefix, spack.store.layout.root))
    buildinfo = spec_dict.get('buildinfo', {})
    old_relative_prefix = buildinfo.get('relative_prefix', new_relative_prefix)
    rel = buildinfo.get('relative_rpaths')
    info = 'old relative prefix %s\nnew relative prefix %s\nrelative rpaths %s'
    tty.debug((info % (old_relative_prefix, new_relative_prefix, rel)))
    with closing(tarfile.open(tarfile_path, 'r')) as tar:
        tar.extractall(path=tmpdir)
    bindist_file = glob.glob(('%s/*/.spack/binary_distribution' % tmpdir))[0]
    workdir = re.sub('/.spack/binary_distribution$', '', bindist_file)
    tty.debug(('workdir %s' % workdir))
    temp_tarfile_name = tarball_name(spec, '.tar')
    temp_tarfile_path = os.path.join(tmpdir, temp_tarfile_name)
    with closing(tarfile.open(temp_tarfile_path, 'w')) as tar:
        tar.add(name=('%s' % workdir), arcname='.')
    with closing(tarfile.open(temp_tarfile_path, 'r')) as tar:
        tar.extractall(spec.prefix)
    os.remove(temp_tarfile_path)
    os.remove(tarfile_path)
    os.remove(specfile_path)
    try:
        relocate_package(spec, allow_root)
    except Exception as e:
        shutil.rmtree(spec.prefix)
        raise e
    else:
        manifest_file = os.path.join(spec.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name)
        if (not os.path.exists(manifest_file)):
            spec_id = spec.format('{name}/{hash:7}')
            tty.warn(('No manifest file in tarball for spec %s' % spec_id))
    finally:
        shutil.rmtree(tmpdir)
        if os.path.exists(filename):
            os.remove(filename)
extract binary tarball for given package into install area
def extract_tarball(spec, filename, allow_root=False, unsigned=False, force=False):
    '\n    \n    '
    if os.path.exists(spec.prefix):
        if force:
            shutil.rmtree(spec.prefix)
        else:
            raise NoOverwriteException(str(spec.prefix))
    tmpdir = tempfile.mkdtemp()
    stagepath = os.path.dirname(filename)
    spackfile_name = tarball_name(spec, '.spack')
    spackfile_path = os.path.join(stagepath, spackfile_name)
    tarfile_name = tarball_name(spec, '.tar.gz')
    tarfile_path = os.path.join(tmpdir, tarfile_name)
    specfile_name = tarball_name(spec, '.spec.yaml')
    specfile_path = os.path.join(tmpdir, specfile_name)
    with closing(tarfile.open(spackfile_path, 'r')) as tar:
        tar.extractall(tmpdir)
    if (not os.path.exists(tarfile_path)):
        tarfile_name = tarball_name(spec, '.tar.bz2')
        tarfile_path = os.path.join(tmpdir, tarfile_name)
    if (not unsigned):
        if os.path.exists(('%s.asc' % specfile_path)):
            try:
                suppress = config.get('config:suppress_gpg_warnings', False)
                Gpg.verify(('%s.asc' % specfile_path), specfile_path, suppress)
            except Exception as e:
                shutil.rmtree(tmpdir)
                raise e
        else:
            shutil.rmtree(tmpdir)
            raise NoVerifyException('Package spec file failed signature verification.\nUse spack buildcache keys to download and install a key for verification from the mirror.')
    checksum = checksum_tarball(tarfile_path)
    spec_dict = {}
    with open(specfile_path, 'r') as inputfile:
        content = inputfile.read()
        spec_dict = syaml.load(content)
    bchecksum = spec_dict['binary_cache_checksum']
    if (bchecksum['hash'] != checksum):
        shutil.rmtree(tmpdir)
        raise NoChecksumException('Package tarball failed checksum verification.\nIt cannot be installed.')
    new_relative_prefix = str(os.path.relpath(spec.prefix, spack.store.layout.root))
    buildinfo = spec_dict.get('buildinfo', {})
    old_relative_prefix = buildinfo.get('relative_prefix', new_relative_prefix)
    rel = buildinfo.get('relative_rpaths')
    info = 'old relative prefix %s\nnew relative prefix %s\nrelative rpaths %s'
    tty.debug((info % (old_relative_prefix, new_relative_prefix, rel)))
    with closing(tarfile.open(tarfile_path, 'r')) as tar:
        tar.extractall(path=tmpdir)
    bindist_file = glob.glob(('%s/*/.spack/binary_distribution' % tmpdir))[0]
    workdir = re.sub('/.spack/binary_distribution$', , bindist_file)
    tty.debug(('workdir %s' % workdir))
    temp_tarfile_name = tarball_name(spec, '.tar')
    temp_tarfile_path = os.path.join(tmpdir, temp_tarfile_name)
    with closing(tarfile.open(temp_tarfile_path, 'w')) as tar:
        tar.add(name=('%s' % workdir), arcname='.')
    with closing(tarfile.open(temp_tarfile_path, 'r')) as tar:
        tar.extractall(spec.prefix)
    os.remove(temp_tarfile_path)
    os.remove(tarfile_path)
    os.remove(specfile_path)
    try:
        relocate_package(spec, allow_root)
    except Exception as e:
        shutil.rmtree(spec.prefix)
        raise e
    else:
        manifest_file = os.path.join(spec.prefix, spack.store.layout.metadata_dir, spack.store.layout.manifest_file_name)
        if (not os.path.exists(manifest_file)):
            spec_id = spec.format('{name}/{hash:7}')
            tty.warn(('No manifest file in tarball for spec %s' % spec_id))
    finally:
        shutil.rmtree(tmpdir)
        if os.path.exists(filename):
            os.remove(filename)