-
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
10 changed files
with
400 additions
and
42 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 |
---|---|---|
|
@@ -59,7 +59,8 @@ | |
"bundle": {}, | ||
"benchmark": {}, | ||
"pkg-ignore": {}, | ||
"mv": {} | ||
"mv": {}, | ||
"rm": {} | ||
} | ||
|
||
|
||
|
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,75 @@ | ||
''' | ||
Remove package(s) from a repository. | ||
''' | ||
from __future__ import print_function | ||
import sys | ||
|
||
|
||
def setup_parser(parser, completions=False): | ||
group = parser.add_mutually_exclusive_group() | ||
group.add_argument( | ||
"-p", "--package", | ||
help="remove the specified package (eg 'foo-1.2.3'). This will work " | ||
"even if the package is currently ignored.") | ||
group.add_argument( | ||
"-i", "--ignored-since", type=int, metavar="DAYS", | ||
help="remove all packages that have been ignored for >= DAYS") | ||
|
||
parser.add_argument( | ||
"--dry-run", action="store_true", | ||
help="dry run mode") | ||
parser.add_argument( | ||
"PATH", nargs='?', | ||
help="the repository containing the package(s) to remove.") | ||
|
||
|
||
def remove_package(opts, parser): | ||
from rez.vendor.version.requirement import VersionedObject | ||
from rez.package_remove import remove_package | ||
|
||
if opts.dry_run: | ||
parser.error("--dry-run is not supported with --package") | ||
|
||
if not opts.PATH: | ||
parser.error("Must specify PATH with --package") | ||
|
||
obj = VersionedObject(opts.package) | ||
|
||
if remove_package(obj.name, obj.version, opts.PATH): | ||
print("Package removed.") | ||
else: | ||
print("Package not found.", file=sys.stderr) | ||
sys.exit(1) | ||
|
||
|
||
def remove_ignored_since(opts, parser): | ||
from rez.package_remove import remove_packages_ignored_since | ||
|
||
if opts.PATH: | ||
paths = [opts.PATH] | ||
else: | ||
paths = None | ||
|
||
num_removed = remove_packages_ignored_since( | ||
days=opts.ignored_since, | ||
paths=paths, | ||
dry_run=opts.dry_run, | ||
verbose=opts.verbose | ||
) | ||
|
||
if num_removed: | ||
if opts.dry_run: | ||
print("%d packages would be removed." % num_removed) | ||
else: | ||
print("%d packages were removed." % num_removed) | ||
else: | ||
print("No packages were removed.") | ||
|
||
|
||
def command(opts, parser, extra_arg_groups=None): | ||
if opts.package: | ||
remove_package(opts, parser) | ||
elif opts.ignored_since is not None: | ||
remove_ignored_since(opts, parser) | ||
else: | ||
parser.error("Must specify either --package or --ignored-since") |
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,61 @@ | ||
from rez.package_repository import package_repository_manager | ||
from rez.vendor.version.version import Version | ||
from rez.utils.logging_ import print_info | ||
from rez.vendor.six import six | ||
from rez.config import config | ||
|
||
|
||
basestring = six.string_types[0] | ||
|
||
|
||
def remove_package(name, version, path): | ||
"""Remove a package from its repository. | ||
Note that you are able to remove a package that is hidden (ie ignored). | ||
This is why a Package instance is not specified (if the package were hidden, | ||
you wouldn't be able to get one). | ||
Args: | ||
name (str): Name of package. | ||
version (Version or str): Version of the package, eg '1.0.0' | ||
path (str): Package repository path containing the package. | ||
Returns: | ||
bool: True if the package was removed, False if package not found. | ||
""" | ||
if isinstance(version, basestring): | ||
version = Version(version) | ||
|
||
repo = package_repository_manager.get_repository(path) | ||
return repo.remove_package(name, version) | ||
|
||
|
||
def remove_packages_ignored_since(days, paths=None, dry_run=False, verbose=False): | ||
"""Remove packages ignored for >= specified number of days. | ||
Args: | ||
days (int): Remove packages ignored >= this many days | ||
paths (list of str, optional): Paths to search for packages, defaults | ||
to `config.packages_path`. | ||
dry_run: Dry run mode | ||
verbose (bool): Verbose mode | ||
Returns: | ||
int: Number of packages removed. In dry-run mode, returns the number of | ||
packages that _would_ be removed. | ||
""" | ||
num_removed = 0 | ||
|
||
for path in (paths or config.packages_path): | ||
repo = package_repository_manager.get_repository(path) | ||
|
||
if verbose: | ||
print_info("Searching %s...", repo) | ||
|
||
num_removed += repo.remove_ignored_since( | ||
days=days, | ||
dry_run=dry_run, | ||
verbose=verbose | ||
) | ||
|
||
return num_removed |
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
Oops, something went wrong.