@contextmanager<EOL>def _extract_to_tempdir(archive_filename):
if not os.path.exists(archive_filename):<EOL><INDENT>raise Exception("<STR_LIT>" % (archive_filename))<EOL><DEDENT>tempdir = tempfile.mkdtemp(prefix="<STR_LIT>")<EOL>current_cwd = os.getcwd()<EOL>try:<EOL><INDENT>if tarfile.is_tarfile(archive_filename):<EOL><INDENT>with tarfile.open(archive_filename) as f:<EOL><INDENT>f.extractall(tempdir)<EOL><DEDENT><DEDENT>elif zipfile.is_zipfile(archive_filename):<EOL><INDENT>with zipfile.ZipFile(archive_filename) as f:<EOL><INDENT>f.extractall(tempdir)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception("<STR_LIT>"<EOL>"<STR_LIT>" % archive_filename)<EOL><DEDENT>os.chdir(tempdir)<EOL>yield tempdir<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(current_cwd)<EOL>shutil.rmtree(tempdir)<EOL><DEDENT>
extract the given tarball or zipfile to a tempdir and change
    the cwd to the new tempdir. Delete the tempdir at the end