-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
404 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,8 @@ | |
"yaml2py": {}, | ||
"bundle": {}, | ||
"benchmark": {}, | ||
"pkg-ignore": {} | ||
"pkg-ignore": {}, | ||
"mv": {} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
''' | ||
Move a package from one repository to another. | ||
''' | ||
from __future__ import print_function | ||
|
||
|
||
def setup_parser(parser, completions=False): | ||
parser.add_argument( | ||
"--dest-path", metavar="PATH", required=True, | ||
help="package repository to move PKG to.") | ||
parser.add_argument( | ||
"-k", "--keep-timestamp", action="store_true", | ||
help="keep timestamp of source package.") | ||
parser.add_argument( | ||
"-f", "--force", action="store_true", | ||
help="move package even if it isn't relocatable (use at your own risk)") | ||
pkg_action = parser.add_argument( | ||
"PKG", | ||
help="package to move") | ||
parser.add_argument( | ||
"PATH", nargs='?', | ||
help="The repository containing the package. If not specified, this " | ||
"command will present you with a list to select from.") | ||
|
||
if completions: | ||
from rez.cli._complete_util import PackageCompleter | ||
pkg_action.completer = PackageCompleter | ||
|
||
|
||
def list_repos_containing_pkg(pkg_name, pkg_version): | ||
from rez.config import config | ||
from rez.package_repository import package_repository_manager | ||
import sys | ||
|
||
# search for package in each searchpath | ||
matching_repos = [] | ||
|
||
for path in config.packages_path: | ||
repo = package_repository_manager.get_repository(path) | ||
if repo.get_package(pkg_name, pkg_version): | ||
matching_repos.append(repo) | ||
|
||
if matching_repos: | ||
print("No action taken. Run again, and set PATH to one of:") | ||
for repo in matching_repos: | ||
print(str(repo)) | ||
else: | ||
print("Package not found.", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
def command(opts, parser, extra_arg_groups=None): | ||
from rez.vendor.version.requirement import VersionedObject | ||
from rez.packages import get_package_from_repository | ||
from rez.package_move import move_package | ||
import sys | ||
|
||
obj = VersionedObject(opts.PKG) | ||
|
||
if opts.PATH is None: | ||
list_repos_containing_pkg(obj.name, obj.version) | ||
sys.exit(0) | ||
|
||
# find src pkg | ||
src_pkg = get_package_from_repository(obj.name, obj.version, opts.PATH) | ||
|
||
if src_pkg is None: | ||
print("Package not found.", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
move_package( | ||
package=src_pkg, | ||
dest_repository=opts.dest_path, | ||
keep_timestamp=opts.keep_timestamp, | ||
force=opts.force, | ||
verbose=opts.verbose | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
from rez.exceptions import PackageMoveError | ||
from rez.package_copy import copy_package | ||
from rez.package_repository import package_repository_manager | ||
from rez.utils.logging_ import print_info | ||
from rez.vendor.six import six | ||
|
||
|
||
basestring = six.string_types[0] | ||
|
||
|
||
def move_package(package, dest_repository, keep_timestamp=False, force=False, | ||
verbose=False): | ||
"""Move a package. | ||
Moving a package means copying the package to a destination repo, and | ||
ignoring (ie hiding - not removing) the source package. The package must | ||
not already exist in the destination repo. | ||
Args: | ||
package (`Package`): Package to move. | ||
dest_repository (`PackageRepository` or str): The package repository, or | ||
a package repository path, to move the package into. | ||
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. | ||
force (bool): Move the package regardless of its relocatable attribute. | ||
Use at your own risk (there is no guarantee the resulting package | ||
will be functional). | ||
verbose (bool): Verbose mode. | ||
Returns: | ||
`Package`: The newly created package in the destination repo. | ||
""" | ||
def _info(msg, *nargs): | ||
if verbose: | ||
print_info(msg, *nargs) | ||
|
||
# get dest repo | ||
if isinstance(dest_repository, basestring): | ||
repo_path = dest_repository | ||
dest_pkg_repo = package_repository_manager.get_repository(repo_path) | ||
else: | ||
dest_pkg_repo = dest_repository | ||
|
||
# check that the package doesn't already exist in the dest repo | ||
pkg = dest_pkg_repo.get_package(package.name, package.version) | ||
if pkg: | ||
raise PackageMoveError( | ||
"Package already exists at destination: %s" | ||
% pkg.uri | ||
) | ||
|
||
# move the pkg as atomically as possible: | ||
# | ||
# 1. Hide the dest package (even tho it doesn't exist yet) | ||
# 2. Copy the package | ||
# 3. Unhide the dest package | ||
# 4. Hide the src package | ||
# | ||
|
||
# 1. | ||
dest_pkg_repo.ignore_package( | ||
package.name, package.version, allow_missing=True) | ||
_info("Ignored %s in %s ahead of time", package.qualified_name, dest_pkg_repo) | ||
|
||
try: | ||
# 2. | ||
result = copy_package( | ||
package=package, | ||
dest_repository=dest_pkg_repo, | ||
force=force, | ||
keep_timestamp=keep_timestamp, | ||
verbose=verbose | ||
) | ||
finally: | ||
# 3. | ||
dest_pkg_repo.unignore_package(package.name, package.version) | ||
_info("Unignored %s in %s", package.qualified_name, dest_pkg_repo) | ||
|
||
# 4. | ||
package.repository.ignore_package(package.name, package.version) | ||
_info("Ignored %s", package.uri) | ||
|
||
# finish up | ||
a_dest_variant = result["copied"][0][1] | ||
dest_pkg = a_dest_variant.parent | ||
|
||
_info("Package %s moved to %s", package.uri, dest_pkg.uri) | ||
return dest_pkg |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.