Extract a .zip/.tar.gz archive to a folder.

def unpack_archive(archive_format, archive_path, source_path):
    """Extract a .zip/.tar.gz archive to a folder."""
    if archive_format not in ('zip', 'tar'):
        raise ValueError('Unknown archive format "%s".' % archive_format)
    if archive_format == 'zip':
        with zipfile.ZipFile(archive_path) as archive:
            archive.extractall(source_path)
    if archive_format == 'tar':
        with tarfile.open(archive_path) as archive:
            archive.extractall(source_path)