def copy_package(package, dest_repository, variants=None, shallow=False,<EOL>dest_name=None, dest_version=None, overwrite=False, force=False,<EOL>follow_symlinks=False, dry_run=False, keep_timestamp=False,<EOL>skip_payload=False, overrides=None, verbose=False):
copied = []<EOL>skipped = []<EOL>def finalize():<EOL><INDENT>return {<EOL>"<STR_LIT>": copied,<EOL>"<STR_LIT>": skipped<EOL>}<EOL><DEDENT>if not force and not skip_payload and not package.is_relocatable:<EOL><INDENT>raise PackageCopyError(<EOL>"<STR_LIT>" % package.uri<EOL>)<EOL><DEDENT>if isinstance(dest_repository, basestring):<EOL><INDENT>repo_path = dest_repository<EOL>dest_pkg_repo = package_repository_manager.get_repository(repo_path)<EOL><DEDENT>else:<EOL><INDENT>dest_pkg_repo = dest_repository<EOL><DEDENT>if package.repository == dest_pkg_repo and(dest_name is None or dest_name == package.name) and(dest_version is None or str(dest_version) == str(package.version)):<EOL><INDENT>raise PackageCopyError(<EOL>"<STR_LIT>" % package.uri<EOL>)<EOL><DEDENT>src_variants = []<EOL>for variant in package.iter_variants():<EOL><INDENT>if variants is None or variant.index in variants:<EOL><INDENT>src_variants.append(variant)<EOL><DEDENT><DEDENT>if not src_variants:<EOL><INDENT>return finalize()<EOL><DEDENT>overrides = (overrides or {}).copy()<EOL>if dest_name:<EOL><INDENT>overrides["<STR_LIT:name>"] = dest_name<EOL><DEDENT>if dest_version:<EOL><INDENT>overrides["<STR_LIT:version>"] = dest_version<EOL><DEDENT>new_src_variants = []<EOL>for src_variant in src_variants:<EOL><INDENT>existing_variant = dest_pkg_repo.install_variant(<EOL>src_variant.resource,<EOL>overrides=overrides,<EOL>dry_run=True<EOL>)<EOL>if existing_variant:<EOL><INDENT>if overwrite:<EOL><INDENT>if verbose:<EOL><INDENT>print_info("<STR_LIT>",<EOL>src_variant.uri, existing_variant.uri)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if verbose:<EOL><INDENT>print_info(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>",<EOL>src_variant.uri, existing_variant.uri<EOL>)<EOL><DEDENT>skipped.append((src_variant, existing_variant))<EOL>continue<EOL><DEDENT><DEDENT>new_src_variants.append(src_variant)<EOL><DEDENT>src_variants = new_src_variants<EOL>for i, src_variant in enumerate(src_variants):<EOL><INDENT>if verbose:<EOL><INDENT>print_info("<STR_LIT>",<EOL>src_variant.uri, str(dest_pkg_repo))<EOL><DEDENT>if dry_run:<EOL><INDENT>dest_variant = None<EOL><DEDENT>else:<EOL><INDENT>if not skip_payload:<EOL><INDENT>dest_pkg_repo.pre_variant_install(src_variant.resource)<EOL>if i == <NUM_LIT:0>:<EOL><INDENT>_copy_package_include_modules(<EOL>src_variant.parent,<EOL>dest_pkg_repo,<EOL>overrides=overrides<EOL>)<EOL><DEDENT>_copy_variant_payload(<EOL>src_variant=src_variant,<EOL>dest_pkg_repo=dest_pkg_repo,<EOL>shallow=shallow,<EOL>follow_symlinks=follow_symlinks,<EOL>overrides=overrides,<EOL>verbose=verbose<EOL>)<EOL><DEDENT>overrides_ = overrides.copy()<EOL>if not keep_timestamp and "<STR_LIT>" not in overrides:<EOL><INDENT>overrides_["<STR_LIT>"] = int(time.time())<EOL><DEDENT>dest_variant = dest_pkg_repo.install_variant(<EOL>variant_resource=src_variant.resource,<EOL>overrides=overrides_<EOL>)<EOL><DEDENT>if verbose:<EOL><INDENT>print_info("<STR_LIT>",<EOL>src_variant, dest_variant)<EOL><DEDENT>copied.append((src_variant, dest_variant))<EOL><DEDENT>return finalize()<EOL>
Copy a package from one package repository to another.

    This copies the package definition and payload. The package can also be
    re-named and/or re-versioned using the `dest_name` and `dest_version` args.

    The result is a dict describing which package variants were and were not
    copied. For example:

        {
            "copied": [
                (`Variant`, `Variant`)
            ],
            "skipped": [
                (`Variant`, `Variant`)
            ]
        }

    Each 2-tuple in the 'copied' or 'skipped' list contains the source and
    destination variant respectively. In the 'skipped' list, the source variant
    is the variant that was NOT copied, and the dest variant is the existing
    target variant that caused the source not to be copied. Skipped variants
    will only be present when `overwrite` is False.

    Note:
        Whether or not a package can be copied is determined by its 'relocatable'
        attribute (see the `default_relocatable` config setting for more details).
        An attempt to copy a non-relocatable package will fail. You can override
        this behaviour with the `force` argument.

    Args:
        package (`Package`): Package to copy.
        dest_repository (`PackageRepository` or str): The package repository, or
            a package repository path, to copy the package into.
        variants (list of int): Indexes of variants to build, or all if None.
        shallow (bool): If True, symlinks of each variant's root directory are
            created, rather than the payload being copied.
        dest_name (str): If provided, copy the package to a new package name.
        dest_version (str or `Version`): If provided, copy the package to a new
            version.
        overwrite (bool): Overwrite variants if they already exist in the
            destination package. In this case, the existing payload is removed
            before the new payload is copied.
        force (bool): Copy the package regardless of its relocatable attribute.
            Use at your own risk (there is no guarantee the resulting package
            will be functional).
        follow_symlinks (bool): Follow symlinks when copying package payload,
            rather than copying the symlinks themselves.
        keep_timestamp (bool): By default, a newly copied package will get a
            new timestamp (because that's when it was added to the target repo).
            By setting this option to True, the original package's timestamp
            is kept intact. Note that this will have no effect if variant(s)
            are copied into an existing package.
        skip_payload (bool): If True, do not copy the package payload.
        overrides (dict): See `PackageRepository.install_variant`.
        verbose (bool): Verbose mode.
        dry_run (bool): Dry run mode. Dest variants in the result will be None
            in this case.

    Returns:
        Dict: See comments above.