def clone_bundle(catalog, bundle_name, version, root_path=None, bundle_dir_name=None, flavor=None):

    assert catalog
    assert bundle_name
    assert version

    if root_path is None:
        root_path = '.'

    if bundle_dir_name is None:
        bundle_id = helpers.make_bundle_id(catalog.id, bundle_name)
        bundle_dir_name = helpers.make_bundle_descriptor(bundle_id, version,
                                                         flavor=flavor)

    manifest = catalog.manifest_for_bundle(bundle_name, version)

    if manifest is None:
        raise Exception("manifest not found: %s-%d" % (bundle_name, version))

    if flavor is not None and flavor not in manifest.flavors:
        raise Exception("manifest does not contain flavor '%s'" % (flavor))

    all_files = manifest.get_all_files(flavor=flavor)

    root_dir = os.path.join(root_path, bundle_dir_name)
    utils.makedirs(root_dir)

    for file in all_files:
        dst_path = os.path.join(root_dir, file)

        formats = manifest.formats_for_file(file)
        sha = manifest.sha_for_file(file)

        utils.makedirs(os.path.dirname(dst_path))

        if formats.get(Formats.RAW) is not None:
            format = Formats.RAW
        elif formats.get(Formats.GZ) is not None:
            format = Formats.GZ
        else:
            format = None

        ext = helpers.file_extension_for_format(format)
        with catalog._read_file(sha, ext=ext) as infile:
            b = infile.read()
            if format == Formats.GZ:
                b = utils.gunzip_bytes(b)
            with open(dst_path, 'w+b') as outfile:
                outfile.write(b)

        log.info("Exported %s --> %s" % (sha, dst_path))

    log.info("Exported %d files to '%s'" % (len(all_files), root_dir))


################################################################################
dataset/ETHPy150Open mindsnacks/Zinc/src/zinc/client.py/clone_bundle/original