Пример #1
0
def remove_variant(pkgcache, uri, opts):
    from rez.packages import get_variant_from_uri
    from rez.utils.logging_ import print_info, print_warning, print_error
    from rez.package_cache import PackageCache

    print_info("Removing variant %r from package cache at %s:", uri, pkgcache.path)

    variant = get_variant_from_uri(uri)
    if variant is None:
        print("No such variant: %s" % uri, file=sys.stderr)
        sys.exit(1)

    status = pkgcache.remove_variant(variant)

    if status == PackageCache.VARIANT_NOT_FOUND:
        print_error("No such variant found in cache")
    elif status == PackageCache.VARIANT_COPYING:
        print_warning("Another process is currently caching this variant")
    else:
        print_info("Variant successfully removed")
Пример #2
0
def add_variant(pkgcache, uri, opts):
    from rez.packages import get_variant_from_uri
    from rez.utils.logging_ import print_info, print_warning
    from rez.package_cache import PackageCache

    print_info("Adding variant %r to package cache at %s:", uri, pkgcache.path)

    variant = get_variant_from_uri(uri)
    if variant is None:
        print("No such variant: %s" % uri, file=sys.stderr)
        sys.exit(1)

    destpath, status = pkgcache.add_variant(variant, force=opts.force)

    if status == PackageCache.VARIANT_FOUND:
        print_info("Already exists: %s", destpath)
    elif status == PackageCache.VARIANT_COPYING:
        print_warning("Another process is currently copying to: %s", destpath)
    else:
        print_info("Successfully cached to: %s", destpath)
Пример #3
0
 def test_variant_from_uri(self):
     """Test getting a variant from its uri."""
     package = get_package("variants_py", "2.0")
     for variant in package.iter_variants():
         variant2 = get_variant_from_uri(variant.uri)
         self.assertEqual(variant, variant2)
Пример #4
0
def command(opts, parser, extra_arg_groups=None):
    import os
    import sys

    from rez.config import config
    from rez.package_repository import package_repository_manager
    from rez.package_copy import copy_package
    from rez.utils.formatting import PackageRequest
    from rez.packages import iter_packages, get_variant_from_uri

    if opts.variant_uri:
        if opts.PKG:
            parser.error("Supply PKG or --variant-uri, not both.")
    elif not opts.PKG:
        parser.error("Expected PKG.")

    if (not opts.dest_path) and not (opts.rename or opts.reversion):
        parser.error("--dest-path must be specified unless --rename or "
                     "--reversion are used.")

    # Load the source package.
    #

    if opts.variant_uri:
        variant = get_variant_from_uri(opts.variant_uri)
        if variant is None:
            print("Unknown variant: %s" % opts.variant_uri, file=sys.stderr)
            sys.exit(1)

        src_pkg = variant.parent
        variant_indexes = [variant.index]

    else:
        if opts.paths:
            paths = opts.paths.split(os.pathsep)
            paths = [x for x in paths if x]
        elif opts.no_local:
            paths = config.nonlocal_packages_path
        else:
            paths = None

        req = PackageRequest(opts.PKG)

        it = iter_packages(name=req.name, range_=req.range_, paths=paths)

        src_pkgs = list(it)
        if not src_pkgs:
            print("No matching packages found.", file=sys.stderr)
            sys.exit(1)

        if len(src_pkgs) > 1:
            print("More than one package matches, please choose:",
                  file=sys.stderr)
            for pkg in sorted(src_pkgs, key=lambda x: x.version):
                print(pkg.qualified_name, file=sys.stderr)
            sys.exit(1)

        src_pkg = src_pkgs[0]
        variant_indexes = opts.variants or None

    # Determine repo and perform checks.
    #
    # A common mistake may be to specify a dest package path, rather than the
    # _repo_ path. This would cause a mess, since a package would be installed
    # into a nested location within an existing package.
    #
    if opts.dest_path:
        dest_pkg_repo = package_repository_manager.get_repository(
            opts.dest_path)

        if (not opts.allow_empty) and dest_pkg_repo.is_empty():
            print((
                "Attempting to copy a package into an EMPTY repository. Are you "
                "sure that --dest-path is the correct path? This should not "
                "include package name and/or version."
                "\n\n"
                "If this is a valid new package repository, use the "
                "--allow-empty flag to continue."),
                  file=sys.stderr)
            sys.exit(1)
    else:
        dest_pkg_repo = src_pkg.repository

    # Perform the copy.
    #

    result = copy_package(package=src_pkg,
                          dest_repository=dest_pkg_repo,
                          dest_name=opts.rename,
                          dest_version=opts.reversion,
                          variants=variant_indexes,
                          overwrite=opts.overwrite,
                          shallow=opts.shallow,
                          follow_symlinks=opts.follow_symlinks,
                          keep_timestamp=opts.keep_timestamp,
                          force=opts.force,
                          verbose=opts.verbose,
                          dry_run=opts.dry_run)

    # Print info about the result.
    #

    copied = result["copied"]
    skipped = result["skipped"]

    if opts.dry_run:
        # show a good indication of target variant when it doesn't get created
        path = dest_pkg_repo.get_package_payload_path(
            package_name=opts.rename or src_pkg.name,
            package_version=opts.reversion or src_pkg.version)

        dry_run_uri = path + "/?"
        verb = "would be"
    else:
        verb = "were"

    # specific output for non-varianted packages
    if src_pkg.num_variants == 0:
        if copied:
            dest_pkg = copied[0][1].parent
            print("Copied %s to %s" % (src_pkg.uri, dest_pkg.uri))
        else:
            assert skipped
            dest_pkg = skipped[0][1].parent
            print(
                "Target package already exists: %s. Use 'overwrite' to replace it."
                % dest_pkg.uri)

    # varianted package
    else:
        if copied:
            print("%d variants %s copied:" % (len(copied), verb))

            for src_variant, dest_variant in copied:
                # None possible if dry_run
                if dest_variant is None:
                    dest_uri = dry_run_uri
                else:
                    dest_uri = dest_variant.uri

                print("  %s -> %s" % (src_variant.uri, dest_uri))

        if skipped:
            print("%d variants %s skipped (target exists):" %
                  (len(skipped), verb))
            for src_variant, dest_variant in skipped:
                print("  %s !-> %s" % (src_variant.uri, dest_variant.uri))